set NOT NULL for column with default value

This commit is contained in:
Jan Prochazka
2024-11-18 13:41:29 +01:00
parent 85c4821606
commit 1ce8f6bd1f
4 changed files with 80 additions and 26 deletions

View File

@@ -132,6 +132,7 @@ class MsSqlDumper extends SqlDumper {
} else {
this.dropDefault(oldcol);
if (oldcol.columnName != newcol.columnName) this.renameColumn(oldcol, newcol.columnName);
this.fillNewNotNullDefaults(newcol);
this.put('^alter ^table %f ^alter ^column %i ', oldcol, oldcol.columnName, newcol.columnName);
this.columnDefinition(newcol, { includeDefault: false });
this.endCommand();

View File

@@ -76,10 +76,6 @@ class Dumper extends SqlDumper {
if (!testEqualTypes(oldcol, newcol)) {
this.putCmd('^alter ^table %f ^alter ^column %i ^type %s', oldcol, newcol.columnName, newcol.dataType);
}
if (oldcol.notNull != newcol.notNull) {
if (newcol.notNull) this.putCmd('^alter ^table %f ^alter ^column %i ^set ^not ^null', newcol, newcol.columnName);
else this.putCmd('^alter ^table %f ^alter ^column %i ^drop ^not ^null', newcol, newcol.columnName);
}
if (oldcol.defaultValue != newcol.defaultValue) {
if (newcol.defaultValue == null) {
this.putCmd('^alter ^table %f ^alter ^column %i ^drop ^default', newcol, newcol.columnName);
@@ -92,6 +88,11 @@ class Dumper extends SqlDumper {
);
}
}
if (oldcol.notNull != newcol.notNull) {
this.fillNewNotNullDefaults(newcol);
if (newcol.notNull) this.putCmd('^alter ^table %f ^alter ^column %i ^set ^not ^null', newcol, newcol.columnName);
else this.putCmd('^alter ^table %f ^alter ^column %i ^drop ^not ^null', newcol, newcol.columnName);
}
}
putValue(value) {