fix:fix: removeu duplicate method, simplify changeColumnComment

This commit is contained in:
Pavel
2025-07-31 17:46:51 +02:00
parent d151114f08
commit 888e284f84

View File

@@ -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);