change column nullablility - works (without SQLite - table recreate needed)

This commit is contained in:
Jan Prochazka
2021-07-01 12:01:24 +02:00
parent 7a10b85b4c
commit 35eb5716a5
5 changed files with 57 additions and 17 deletions

View File

@@ -1,4 +1,4 @@
const { SqlDumper } = global.DBGATE_TOOLS;
const { SqlDumper, testEqualColumns } = global.DBGATE_TOOLS;
class MsSqlDumper extends SqlDumper {
autoIncrement() {
@@ -88,6 +88,21 @@ class MsSqlDumper extends SqlDumper {
this.putCmd("^execute sp_rename '%f.%i', '%s', 'COLUMN'", column, column.columnName, newcol);
}
changeColumn(oldcol, newcol, constraints) {
if (testEqualColumns(oldcol, newcol, false, false)) {
this.dropDefault(oldcol);
if (oldcol.columnName != newcol.columnName) this.renameColumn(oldcol, newcol.columnName);
this.createDefault(oldcol);
} else {
this.dropDefault(oldcol);
if (oldcol.columnName != newcol.columnName) this.renameColumn(oldcol, newcol.columnName);
this.put('^alter ^table %f ^alter ^column %i ', oldcol, oldcol.columnName, newcol.columnName);
this.columnDefinition(newcol, { includeDefault: false });
this.endCommand();
this.createDefault(oldcol);
}
}
renameConstraint(cnt, newname) {
if (cnt.constraintType == 'index')
this.putCmd("^execute sp_rename '%f.%i', '%s', 'INDEX'", cnt, cnt.constraintName, newname);