mysql change column to not null

This commit is contained in:
Jan Prochazka
2024-11-18 14:56:59 +01:00
parent 2ae98d0c2d
commit c0c9c7be20
6 changed files with 20 additions and 5 deletions

View File

@@ -117,7 +117,12 @@ async function testDatabaseDeploy(engine, conn, driver, dbModelsYaml, options) {
const dbhan = conn.isPreparedOnly ? await connectUtility(driver, conn, 'read') : conn;
const structure = await driver.analyseFull(dbhan);
if (conn.isPreparedOnly) await driver.close(dbhan);
checkStructure(engine, structure, finalCheckAgainstModel ?? dbModelsYaml[dbModelsYaml.length - 1], options);
checkStructure(
engine,
structure,
finalCheckAgainstModel ?? _.findLast(dbModelsYaml, x => _.isArray(x)),
options
);
}
describe('Deploy database', () => {
@@ -452,6 +457,7 @@ describe('Deploy database', () => {
},
},
],
'insert into t1 (id) values (3);',
]);
const res1 = await driver.query(conn, `select val from t1 where id = 1`);
@@ -459,6 +465,9 @@ describe('Deploy database', () => {
const res2 = await driver.query(conn, `select val from t1 where id = 2`);
expect(res2.rows[0].val).toEqual(20);
const res3 = await driver.query(conn, `select val from t1 where id = 3`);
expect(res2.rows[0].val).toEqual(20);
})
);

View File

@@ -188,9 +188,9 @@ const filterLocal = [
// filter local testing
'-MySQL',
'-MariaDB',
'PostgreSQL',
'-PostgreSQL',
'-SQL Server',
'-SQLite',
'SQLite',
'-CockroachDB',
'-ClickHouse',
];

View File

@@ -263,7 +263,7 @@ export class SqlDumper implements AlterProcessor {
}
columnDefault(column: ColumnInfo) {
if (column.defaultConstraint != null) {
if (column.defaultConstraint != null && this.dialect?.namedDefaultConstraint) {
this.put(' ^constraint %i ^default %s ', column.defaultConstraint, column.defaultValue);
} else {
this.put(' ^default %s ', column.defaultValue);

View File

@@ -37,6 +37,7 @@ export interface SqlDialect {
renameSqlObject?: boolean;
multipleSchema?: boolean;
filteredIndexes?: boolean;
namedDefaultConstraint?: boolean;
specificNullabilityImplementation?: boolean;
omitForeignKeys?: boolean;

View File

@@ -42,6 +42,7 @@ const dialect = {
filteredIndexes: true,
dropReferencesWhenDropTable: true,
namedDefaultConstraint: true,
columnProperties: {
isSparse: true,

View File

@@ -32,6 +32,10 @@ class Dumper extends SqlDumper {
}
changeColumn(oldcol, newcol, constraints) {
this.fillNewNotNullDefaults({
...newcol,
columnName: oldcol.columnName,
});
this.put('^alter ^table %f ^change ^column %i %i ', oldcol, oldcol.columnName, newcol.columnName);
this.columnDefinition(newcol);
this.inlineConstraints(constraints);
@@ -91,7 +95,7 @@ class Dumper extends SqlDumper {
}
selectScopeIdentity() {
this.put('^select ^last_insert_id()')
this.put('^select ^last_insert_id()');
}
}