alter table fixes WIP

This commit is contained in:
Jan Prochazka 2024-09-13 14:23:37 +02:00
parent c1106c1b01
commit b366a7d451
4 changed files with 40 additions and 31 deletions

View File

@ -139,7 +139,7 @@ const engines = [
local: {
databaseUrl: 'http://localhost:15005',
},
// skipOnCI: true,
skipOnCI: true,
objects: [views],
skipDataModifications: true,
skipReferences: true,

View File

@ -315,8 +315,12 @@ export class AlterPlan {
return res;
}
if (op.operationType == 'changeColumn') {
const constraints = this._getDependendColumnConstraints(op.oldObject, this.dialect.changeColumnDependencies);
for (const [testedOperationType, testedDependencies, testedObject] of [
['changeColumn', this.dialect.changeColumnDependencies, (op as AlterOperation_ChangeColumn).oldObject],
['renameColumn', this.dialect.renameColumnDependencies, (op as AlterOperation_RenameColumn).object],
]) {
if (op.operationType == testedOperationType) {
const constraints = this._getDependendColumnConstraints(testedObject as ColumnInfo, testedDependencies);
if (constraints.length > 0 && this.opts.noDropConstraint) {
return [];
@ -345,6 +349,7 @@ export class AlterPlan {
}
return res;
}
}
if (op.operationType == 'dropTable') {
return [
@ -392,7 +397,8 @@ export class AlterPlan {
this._testTableRecreate(op, 'dropColumn', this.dialect.dropColumn, 'oldObject') ||
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') || [op]
this._testTableRecreate(op, 'changeColumn', this.dialect.changeColumn, 'newObject') ||
this._testTableRecreate(op, 'renameColumn', true, 'object') || [op]
);
});
@ -473,7 +479,7 @@ export class AlterPlan {
}
} else {
// @ts-ignore
const oldObject: TableInfo = op.oldObject;
const oldObject: TableInfo = op.oldObject || op.object;
if (oldObject) {
const recreated = recreates[`${oldObject.schemaName}||${oldObject.pureName}`];
if (recreated) {

View File

@ -17,6 +17,7 @@ export interface SqlDialect {
dropColumnDependencies?: string[];
changeColumnDependencies?: string[];
renameColumnDependencies?: string[];
dropIndexContainsTableSpec?: boolean;

View File

@ -91,7 +91,9 @@ const dialect = {
rangeSelect: true,
stringEscapeChar: "'",
fallbackDataType: 'String',
dropColumnDependencies: ['primaryKey', 'sortingKey'],
changeColumnDependencies: ['primaryKey', 'sortingKey'],
renameColumnDependencies: ['primaryKey', 'sortingKey'],
createColumn: true,
dropColumn: true,
changeColumn: true,