diff --git a/plugins/dbgate-plugin-mssql/src/frontend/MsSqlDumper.js b/plugins/dbgate-plugin-mssql/src/frontend/MsSqlDumper.js index 41bb495c0..66ddde21d 100644 --- a/plugins/dbgate-plugin-mssql/src/frontend/MsSqlDumper.js +++ b/plugins/dbgate-plugin-mssql/src/frontend/MsSqlDumper.js @@ -161,32 +161,15 @@ class MsSqlDumper extends SqlDumper { this.endCommand(); } - /** - * @param {import('dbgate-types').TableInfo} table - */ - createColumnComment(table) { - const { schemaName, pureName, objectComment } = table; - if (!objectComment) return; - - this.put('&>^exec sp_addextendedproperty&n'); - this.put(`@value = N'%s',&n`, objectComment); - this.put("@level0type = N'SCHEMA', @level0name = '%s',&n", schemaName); - this.put("@level1type = N'TABLE', @level1name = '%s'&n&<", pureName); - this.endCommand(); - } - /** * @param {import('dbgate-types').ColumnInfo} oldcol * @param {import('dbgate-types').ColumnInfo} newcol */ changeColumnComment(oldcol, newcol) { - if (oldcol.columnComment == newcol.columnComment) return; - if (oldcol.columnComment && !newcol.columnComment) { - this.dropColumnComment(newcol); - } else { - this.dropColumnComment(newcol); - this.createColumnComment(newcol); - } + if (oldcol.columnComment === newcol.columnComment) return; + + if (oldcol.columnComment) this.dropColumnComment(newcol); + if (newcol.columnComment) this.createColumnComment(newcol); } /** @@ -211,7 +194,7 @@ class MsSqlDumper extends SqlDumper { if (!columnComment) return; this.put('&>^exec sp_addextendedproperty&n'); - this.put("@name = N'MS_Description',"); + this.put("@name = N'MS_Description', "); this.put(`@value = N'%s',&n`, columnComment); this.put("@level0type = N'SCHEMA', @level0name = '%s',&n", schemaName); this.put("@level1type = N'TABLE', @level1name = '%s',&n", pureName); @@ -219,6 +202,17 @@ class MsSqlDumper extends SqlDumper { this.endCommand(); } + /** + * @param {import('dbgate-types').TableInfo} table + */ + createTable(table) { + super.createTable(table); + + for (const column of table.columns || []) { + this.createColumnComment(column); + } + } + changeColumn(oldcol, newcol, constraints) { if (testEqualColumns(oldcol, newcol, false, false, { ignoreComments: true })) { this.dropDefault(oldcol);