mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 03:53:57 +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 dbhan = conn.isPreparedOnly ? await connectUtility(driver, conn, 'read') : conn;
|
||||||
const structure = await driver.analyseFull(dbhan);
|
const structure = await driver.analyseFull(dbhan);
|
||||||
if (conn.isPreparedOnly) await driver.close(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', () => {
|
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`);
|
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`);
|
const res2 = await driver.query(conn, `select val from t1 where id = 2`);
|
||||||
expect(res2.rows[0].val).toEqual(20);
|
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
|
// filter local testing
|
||||||
'-MySQL',
|
'-MySQL',
|
||||||
'-MariaDB',
|
'-MariaDB',
|
||||||
'PostgreSQL',
|
'-PostgreSQL',
|
||||||
'-SQL Server',
|
'-SQL Server',
|
||||||
'-SQLite',
|
'SQLite',
|
||||||
'-CockroachDB',
|
'-CockroachDB',
|
||||||
'-ClickHouse',
|
'-ClickHouse',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ export class SqlDumper implements AlterProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
columnDefault(column: ColumnInfo) {
|
columnDefault(column: ColumnInfo) {
|
||||||
if (column.defaultConstraint != null) {
|
if (column.defaultConstraint != null && this.dialect?.namedDefaultConstraint) {
|
||||||
this.put(' ^constraint %i ^default %s ', column.defaultConstraint, column.defaultValue);
|
this.put(' ^constraint %i ^default %s ', column.defaultConstraint, column.defaultValue);
|
||||||
} else {
|
} else {
|
||||||
this.put(' ^default %s ', column.defaultValue);
|
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;
|
renameSqlObject?: boolean;
|
||||||
multipleSchema?: boolean;
|
multipleSchema?: boolean;
|
||||||
filteredIndexes?: boolean;
|
filteredIndexes?: boolean;
|
||||||
|
namedDefaultConstraint?: boolean;
|
||||||
|
|
||||||
specificNullabilityImplementation?: boolean;
|
specificNullabilityImplementation?: boolean;
|
||||||
omitForeignKeys?: boolean;
|
omitForeignKeys?: boolean;
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ const dialect = {
|
|||||||
filteredIndexes: true,
|
filteredIndexes: true,
|
||||||
|
|
||||||
dropReferencesWhenDropTable: true,
|
dropReferencesWhenDropTable: true,
|
||||||
|
namedDefaultConstraint: true,
|
||||||
|
|
||||||
columnProperties: {
|
columnProperties: {
|
||||||
isSparse: true,
|
isSparse: true,
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ class Dumper extends SqlDumper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
changeColumn(oldcol, newcol, constraints) {
|
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.put('^alter ^table %f ^change ^column %i %i ', oldcol, oldcol.columnName, newcol.columnName);
|
||||||
this.columnDefinition(newcol);
|
this.columnDefinition(newcol);
|
||||||
this.inlineConstraints(constraints);
|
this.inlineConstraints(constraints);
|
||||||
@@ -91,7 +95,7 @@ class Dumper extends SqlDumper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
selectScopeIdentity() {
|
selectScopeIdentity() {
|
||||||
this.put('^select ^last_insert_id()')
|
this.put('^select ^last_insert_id()');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user