Skip to content

Commit bbf3b8e

Browse files
HCK-15104: Script generation options and ALTER script (#75)
* HCK-15104: Script generation options and ALTER script * fix: view columns generation * update default values to SQL simple * remove unused method * secondary index as a separate statement * fix * create secondary index by default if no type * remove unused * fix creating indexes
1 parent 57351a9 commit bbf3b8e

File tree

8 files changed

+885
-215
lines changed

8 files changed

+885
-215
lines changed

forward_engineering/config.json

Lines changed: 431 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,79 @@
11
module.exports = {
22
createDatabase: 'CREATE DATABASE "${name}" AS ${databaseOptions};',
33
createSession: 'SET SESSION DATABASE "${name}";',
4+
dropDatabase: 'DROP DATABASE "${databaseName}";',
5+
modifyDatabase: 'MODIFY DATABASE "${databaseName}" AS ${databaseOptions};',
6+
commentDatabase: 'COMMENT ON DATABASE ${databaseName}\nIS ${comment};',
7+
48
columnDefinition:
5-
'"${name}" ${type}${inlineLength}${not_null}${uppercase}${caseSpecific}${format}${default}${storageFormat}${characterSet}${withSchema}${autoColumn}${compress}${compressUsing}${decompressUsing}${inlineCheckConstraint}${inlineUniqueConstraint}${inlinePKConstraint}',
9+
'${name}${type}${inlineLength}${not_null}${uppercase}${caseSpecific}${format}${default}${storageFormat}${characterSet}${withSchema}${autoColumn}${compress}${compressUsing}${decompressUsing}${inlineCheckConstraint}${inlineUniqueConstraint}${inlinePKConstraint}',
610
createTable:
711
'CREATE${tableSet}${temporary}${traceTable} TABLE ${name}${tableOptions} (\n' +
812
'\t\t${column_definitions}${keyConstraints}${checkConstraints}${foreignKeyConstraints}\n' +
9-
'\t)${tableIndexes}${tablePreservation};\n',
13+
'\t)${tableIndexes}${tablePreservation};',
1014
createAsSelectTable:
1115
'CREATE${tableSet}${temporary} TABLE ${name}${tableOptions} (\n' +
1216
'\t\t${column_definitions}${keyConstraints}${checkConstraints}${foreignKeyConstraints}\n' +
1317
'\t)' +
1418
'\n\tAS (\n' +
1519
'\t${selectStatement} ' +
16-
'\n\t)${tableIndexes}${tablePreservation};\n',
17-
createErrorTable: 'CREATE ERROR TABLE ${tableName} FOR ${targetDataTable};\n',
20+
'\n\t)${tableIndexes}${tablePreservation};',
21+
createErrorTable: 'CREATE ERROR TABLE ${tableName} FOR ${targetDataTable};',
1822
createForeignTable:
1923
'CREATE FOREIGN TABLE ${name}${tableOptions} (\n' +
2024
'\t\t${column_definitions}${keyConstraints}${checkConstraints}${foreignKeyConstraints}\n' +
2125
'\t)\n' +
2226
'\tUSING (\n' +
2327
'\t${usingOptions}\n' +
24-
'\t)${tableIndexes}${tablePreservation};\n',
28+
'\t)${tableIndexes}${tablePreservation};',
2529
createHashIndex:
2630
'CREATE HASH INDEX ${indexName}${indexOptions} (\n' +
2731
'\t\t${indexKeys}' +
2832
'\n\t)' +
29-
'\n\tON ${tableName}${orderBy};\n',
30-
createJoinIndex: 'CREATE JOIN INDEX ${indexName}${indexOptions}' + '\n\tAS ${selectStatement};\n',
31-
createKeyConstraint: 'CONSTRAINT ${constraintName}${constraintType}${columns}',
33+
'\n\tON ${tableName}${orderBy};',
34+
createJoinIndex: 'CREATE JOIN INDEX ${indexName}${indexOptions}' + '\n\tAS ${selectStatement};',
35+
createKeyConstraint: '${constraintName}${constraintType} (${columns})',
3236
checkConstraint: '${name}${expression}',
33-
createForeignKeyConstraint: 'FOREIGN KEY (${foreignKey}) REFERENCES ${checkOption} ${primaryTable} (${primaryKey})',
34-
createView: 'CREATE${recursive} VIEW ${name} (\n' + '\t${columnList}\n' + ')\nAS ${selectStatement};\n',
37+
38+
createForeignKeyConstraint:
39+
'${constraintName}FOREIGN KEY (${foreignKey}) REFERENCES ${checkOption} ${primaryTable} (${primaryKey})',
40+
dropForeignKeyUnnamed:
41+
'ALTER TABLE ${tableName} DROP FOREIGN KEY (${foreignKey}) REFERENCES ${primaryTable} (${primaryKey});',
42+
43+
createView: 'CREATE${recursive} VIEW ${name} (\n' + '\t${columnList}\n' + ')\nAS ${selectStatement};',
3544
viewSelectStatement: 'SELECT ${keys}\n\tFROM ${tableName}',
3645
createStructuredType:
37-
'CREATE TYPE ${typeName} AS (\n' + '\t${columnDefinitions}' + '\n)\n' + 'NOT FINAL${methodSpecification};\n',
38-
createDistinctType: 'CREATE TYPE ${typeName} AS ${baseType} FINAL${methodSpecification};\n',
39-
createArrayType: 'CREATE TYPE ${typeName} AS ${baseType}${default};\n',
40-
41-
dropDatabase: 'DROP DATABASE "${databaseName}";\n',
42-
modifyDatabase: 'MODIFY DATABASE "${databaseName}" AS ${databaseOptions};\n',
46+
'CREATE TYPE ${typeName} AS (\n' + '\t${columnDefinitions}' + '\n)\n' + 'NOT FINAL${methodSpecification};',
47+
createDistinctType: 'CREATE TYPE ${typeName} AS ${baseType} FINAL${methodSpecification};',
48+
createArrayType: 'CREATE TYPE ${typeName} AS ${baseType}${default};',
4349

44-
dropTable: 'DROP ${temporary}TABLE ${name};\n',
50+
dropTable: 'DROP ${temporary}TABLE ${name};',
4551
alterTable: 'ALTER TABLE ${tableName}${tableOptions}${alterStatement};',
52+
renameTable: 'RENAME TABLE ${oldName} TO ${newName};',
53+
commentTable: 'COMMENT ON TABLE ${tableName}\nIS ${comment};',
4654

4755
addColumn: ' ADD ${columnDefinition}',
56+
alterColumn: 'ALTER TABLE ${tableName} ADD ${columnName} ${columnDefinition};',
4857
dropColumn: ' DROP ${name}',
4958
rename: ' RENAME ${oldName} TO ${newName}',
59+
commentColumn: 'COMMENT ON COLUMN ${columnName}\nIS ${comment};',
5060

5161
dropCheckConstraint: ' DROP CONSTRAINT ${name} CHECK',
52-
addCheckConstraint: ' ADD CONSTRAINT ${name} ${expression}',
53-
modifyCheckConstraint: ' MODIFY CONSTRAINT ${name} ${expression}',
62+
addCheckConstraint: ' ADD ${constraintName}${expression}',
63+
alterCheckConstraint: ' ADD ${constraintName}${expression}',
5464

65+
createSecondaryIndex: 'CREATE ${indexStatement} ON ${tableName};',
5566
dropSecondaryIndex: 'DROP INDEX ${indexName} ON ${tableName};',
5667
dropIndex: 'DROP${indexType} INDEX ${indexName};',
5768

5869
dropView: 'DROP VIEW ${viewName};',
5970
renameView: 'RENAME VIEW ${oldViewName} TO ${newViewName};',
71+
commentView: 'COMMENT ON VIEW ${viewName}\nIS ${comment};',
72+
73+
dropConstraint: 'ALTER TABLE ${tableName} DROP CONSTRAINT ${constraintName};',
74+
75+
alterPrimaryKey: 'ALTER TABLE ${tableName} ADD ${constraintName}PRIMARY KEY (${columns});',
76+
alterUniqueKey: 'ALTER TABLE ${tableName} ADD ${constraintName}UNIQUE (${columns});',
77+
78+
dropUnnamedIndex: 'DROP INDEX (${columns}) ON ${tableName};',
6079
};

0 commit comments

Comments
 (0)