mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 07:56:28 +00:00
mysql change column to not null
This commit is contained in:
@@ -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);
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -188,9 +188,9 @@ const filterLocal = [
|
||||
// filter local testing
|
||||
'-MySQL',
|
||||
'-MariaDB',
|
||||
'PostgreSQL',
|
||||
'-PostgreSQL',
|
||||
'-SQL Server',
|
||||
'-SQLite',
|
||||
'SQLite',
|
||||
'-CockroachDB',
|
||||
'-ClickHouse',
|
||||
];
|
||||
|
||||
@@ -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);
|
||||
|
||||
1
packages/types/dialect.d.ts
vendored
1
packages/types/dialect.d.ts
vendored
@@ -37,6 +37,7 @@ export interface SqlDialect {
|
||||
renameSqlObject?: boolean;
|
||||
multipleSchema?: boolean;
|
||||
filteredIndexes?: boolean;
|
||||
namedDefaultConstraint?: boolean;
|
||||
|
||||
specificNullabilityImplementation?: boolean;
|
||||
omitForeignKeys?: boolean;
|
||||
|
||||
@@ -42,6 +42,7 @@ const dialect = {
|
||||
filteredIndexes: true,
|
||||
|
||||
dropReferencesWhenDropTable: true,
|
||||
namedDefaultConstraint: true,
|
||||
|
||||
columnProperties: {
|
||||
isSparse: true,
|
||||
|
||||
@@ -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()');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user