force recreate table when changing autoincrement flag

This commit is contained in:
Jan Prochazka
2024-11-19 10:06:49 +01:00
parent 274fb595a2
commit b0012872fa
6 changed files with 28 additions and 2 deletions

View File

@@ -166,4 +166,14 @@ describe('Alter table', () => {
});
})
);
test.each(engines.map(engine => [engine.label, engine]))(
'Change autoincrement - %s',
testWrapper(async (conn, driver, engine) => {
await testTableDiff(engine, conn, driver, tbl => {
tbl.columns.find(x => x.columnName == 'col_pk').autoIncrement = true;
});
})
);
});

View File

@@ -191,8 +191,8 @@ const filterLocal = [
'-MySQL',
'-MariaDB',
'-PostgreSQL',
'-SQL Server',
'SQLite',
'SQL Server',
'-SQLite',
'-CockroachDB',
'-ClickHouse',
];

View File

@@ -416,6 +416,12 @@ export class AlterPlan {
this._testTableRecreate(op, 'createConstraint', obj => this._canCreateConstraint(obj), 'newObject') ||
this._testTableRecreate(op, 'dropConstraint', obj => this._canDropConstraint(obj), 'oldObject') ||
this._testTableRecreate(op, 'changeColumn', this.dialect.changeColumn, 'newObject') ||
this._testTableRecreate(
op,
'changeColumn',
obj => this._canChangeAutoIncrement(obj, op as AlterOperation_ChangeColumn),
'newObject'
) ||
this._testTableRecreate(op, 'renameColumn', true, 'object') || [op]
);
});
@@ -443,6 +449,13 @@ export class AlterPlan {
return null;
}
_canChangeAutoIncrement(column: ColumnInfo, op: AlterOperation_ChangeColumn) {
if (!!column.autoIncrement != !!op.oldObject.autoIncrement) {
return this.dialect.changeAutoIncrement;
}
return null;
}
_testTableRecreate(
op: AlterOperation,
operationType: string,

View File

@@ -24,6 +24,7 @@ export interface SqlDialect {
createColumn?: boolean;
dropColumn?: boolean;
changeColumn?: boolean;
changeAutoIncrement?: boolean;
createIndex?: boolean;
dropIndex?: boolean;
createForeignKey?: boolean;

View File

@@ -97,6 +97,7 @@ const dialect = {
createColumn: true,
dropColumn: true,
changeColumn: true,
changeAutoIncrement: true,
createIndex: true,
dropIndex: true,
anonymousPrimaryKey: true,

View File

@@ -30,6 +30,7 @@ const dialect = {
createColumn: true,
dropColumn: true,
changeColumn: true,
changeAutoIncrement: true,
createIndex: true,
dropIndex: true,
createForeignKey: true,