Skip to content

Commit 485b6ff

Browse files
fix: used separate statement for adding column comment (#220)
1 parent 36a0457 commit 485b6ff

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

forward_engineering/configs/templates.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,6 @@ module.exports = {
104104
alterTableAddConstraint: 'ALTER TABLE IF EXISTS ${tableName} ADD ${statement};',
105105
alterTableDropNamedConstraint: 'ALTER TABLE IF EXISTS ${tableName} DROP CONSTRAINT ${constraintName};',
106106
alterTableDropStatement: 'ALTER TABLE IF EXISTS ${tableName} DROP ${statement};',
107+
108+
columnComment: 'COMMENT ON COLUMN ${fullName} IS ${comment}',
107109
};

forward_engineering/helpers/alterScriptHelpers/alterEntityHelper.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const getAddCollectionScript =
1616
const { schemaName, databaseName } = getBaseAndContainerNames(collection, getName);
1717
const jsonSchema = {
1818
...collection,
19-
...(_.omit(collection?.role, 'properties') || {}),
19+
..._.omit(collection?.role, 'properties'),
2020
};
2121
const columnDefinitions = _.toPairs(jsonSchema.properties).map(([name, column]) =>
2222
createColumnDefinitionBySchema({
@@ -47,7 +47,7 @@ const getAddCollectionScript =
4747
const getDeleteCollectionScript = collection => {
4848
const jsonData = {
4949
...collection,
50-
...(_.omit(collection?.role, 'properties') || {}),
50+
..._.omit(collection?.role, 'properties'),
5151
};
5252
const { schemaName, databaseName, tableName } = getNames(jsonData, getName, getEntityName);
5353
const fullName = getFullName(databaseName, getFullName(schemaName, tableName));
@@ -66,7 +66,7 @@ const getAddColumnScript =
6666
collection => {
6767
const collectionSchema = {
6868
...collection,
69-
...(_.omit(collection?.role, 'properties') || {}),
69+
..._.omit(collection?.role, 'properties'),
7070
};
7171
const { schemaName, databaseName, tableName } = getNames(collectionSchema, getName, getEntityName);
7272
const fullName = getFullName(databaseName, getFullName(schemaName, tableName));
@@ -92,7 +92,7 @@ const getAddColumnScript =
9292
const getDeleteColumnScript = collection => {
9393
const collectionSchema = {
9494
...collection,
95-
...(_.omit(collection?.role, 'properties') || {}),
95+
..._.omit(collection?.role, 'properties'),
9696
};
9797
const { schemaName, databaseName, tableName } = getNames(collectionSchema, getName, getEntityName);
9898
const fullName = getFullName(databaseName, getFullName(schemaName, tableName));
@@ -165,9 +165,9 @@ const getModifyColumnScript =
165165

166166
// new or modified comment
167167
if (oldComment !== comment) {
168-
return assignTemplates(templates.alterTable, {
169-
name: fullName,
170-
action: `MODIFY COLUMN ${columnName} COMMENT = ${escapeString(scriptFormat, comment)}`,
168+
return assignTemplates(templates.columnComment, {
169+
fullName: `${fullName}.${columnName}`,
170+
comment: escapeString(scriptFormat, comment),
171171
});
172172
}
173173
})

0 commit comments

Comments
 (0)