mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
alter table fixes WIP
This commit is contained in:
parent
c1106c1b01
commit
b366a7d451
@ -139,7 +139,7 @@ const engines = [
|
|||||||
local: {
|
local: {
|
||||||
databaseUrl: 'http://localhost:15005',
|
databaseUrl: 'http://localhost:15005',
|
||||||
},
|
},
|
||||||
// skipOnCI: true,
|
skipOnCI: true,
|
||||||
objects: [views],
|
objects: [views],
|
||||||
skipDataModifications: true,
|
skipDataModifications: true,
|
||||||
skipReferences: true,
|
skipReferences: true,
|
||||||
|
@ -315,35 +315,40 @@ export class AlterPlan {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (op.operationType == 'changeColumn') {
|
for (const [testedOperationType, testedDependencies, testedObject] of [
|
||||||
const constraints = this._getDependendColumnConstraints(op.oldObject, this.dialect.changeColumnDependencies);
|
['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) {
|
if (constraints.length > 0 && this.opts.noDropConstraint) {
|
||||||
return [];
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const res: AlterOperation[] = [
|
||||||
|
...constraints.map(oldObject => {
|
||||||
|
const opRes: AlterOperation = {
|
||||||
|
operationType: 'dropConstraint',
|
||||||
|
oldObject,
|
||||||
|
};
|
||||||
|
return opRes;
|
||||||
|
}),
|
||||||
|
op,
|
||||||
|
..._.reverse([...constraints]).map(newObject => {
|
||||||
|
const opRes: AlterOperation = {
|
||||||
|
operationType: 'createConstraint',
|
||||||
|
newObject,
|
||||||
|
};
|
||||||
|
return opRes;
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
|
if (constraints.length > 0) {
|
||||||
|
this.recreates.constraints += 1;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
const res: AlterOperation[] = [
|
|
||||||
...constraints.map(oldObject => {
|
|
||||||
const opRes: AlterOperation = {
|
|
||||||
operationType: 'dropConstraint',
|
|
||||||
oldObject,
|
|
||||||
};
|
|
||||||
return opRes;
|
|
||||||
}),
|
|
||||||
op,
|
|
||||||
..._.reverse([...constraints]).map(newObject => {
|
|
||||||
const opRes: AlterOperation = {
|
|
||||||
operationType: 'createConstraint',
|
|
||||||
newObject,
|
|
||||||
};
|
|
||||||
return opRes;
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
|
|
||||||
if (constraints.length > 0) {
|
|
||||||
this.recreates.constraints += 1;
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (op.operationType == 'dropTable') {
|
if (op.operationType == 'dropTable') {
|
||||||
@ -392,7 +397,8 @@ export class AlterPlan {
|
|||||||
this._testTableRecreate(op, 'dropColumn', this.dialect.dropColumn, 'oldObject') ||
|
this._testTableRecreate(op, 'dropColumn', this.dialect.dropColumn, 'oldObject') ||
|
||||||
this._testTableRecreate(op, 'createConstraint', obj => this._canCreateConstraint(obj), 'newObject') ||
|
this._testTableRecreate(op, 'createConstraint', obj => this._canCreateConstraint(obj), 'newObject') ||
|
||||||
this._testTableRecreate(op, 'dropConstraint', obj => this._canDropConstraint(obj), 'oldObject') ||
|
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 {
|
} else {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const oldObject: TableInfo = op.oldObject;
|
const oldObject: TableInfo = op.oldObject || op.object;
|
||||||
if (oldObject) {
|
if (oldObject) {
|
||||||
const recreated = recreates[`${oldObject.schemaName}||${oldObject.pureName}`];
|
const recreated = recreates[`${oldObject.schemaName}||${oldObject.pureName}`];
|
||||||
if (recreated) {
|
if (recreated) {
|
||||||
|
1
packages/types/dialect.d.ts
vendored
1
packages/types/dialect.d.ts
vendored
@ -17,6 +17,7 @@ export interface SqlDialect {
|
|||||||
|
|
||||||
dropColumnDependencies?: string[];
|
dropColumnDependencies?: string[];
|
||||||
changeColumnDependencies?: string[];
|
changeColumnDependencies?: string[];
|
||||||
|
renameColumnDependencies?: string[];
|
||||||
|
|
||||||
dropIndexContainsTableSpec?: boolean;
|
dropIndexContainsTableSpec?: boolean;
|
||||||
|
|
||||||
|
@ -91,7 +91,9 @@ const dialect = {
|
|||||||
rangeSelect: true,
|
rangeSelect: true,
|
||||||
stringEscapeChar: "'",
|
stringEscapeChar: "'",
|
||||||
fallbackDataType: 'String',
|
fallbackDataType: 'String',
|
||||||
|
dropColumnDependencies: ['primaryKey', 'sortingKey'],
|
||||||
|
changeColumnDependencies: ['primaryKey', 'sortingKey'],
|
||||||
|
renameColumnDependencies: ['primaryKey', 'sortingKey'],
|
||||||
createColumn: true,
|
createColumn: true,
|
||||||
dropColumn: true,
|
dropColumn: true,
|
||||||
changeColumn: true,
|
changeColumn: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user