alter table - change column dependencies

This commit is contained in:
Jan Prochazka
2021-09-09 09:09:06 +02:00
parent e568adc825
commit b659136f64
3 changed files with 26 additions and 1 deletions

View File

@@ -62,6 +62,7 @@ const TESTED_COLUMNS = ['col_pk', 'col_std', 'col_def', 'col_fk', 'col_ref', 'co
// const TESTED_COLUMNS = ['col_idx'];
// const TESTED_COLUMNS = ['col_def'];
// const TESTED_COLUMNS = ['col_std'];
// const TESTED_COLUMNS = ['col_ref'];
function engines_columns_source() {
return _.flatten(engines.map(engine => TESTED_COLUMNS.map(column => [engine.label, column, engine])));

View File

@@ -222,6 +222,30 @@ export class AlterPlan {
];
return res;
}
if (op.operationType == 'changeColumn') {
const constraints = this._getDependendColumnConstraints(op.oldObject, this.dialect.changeColumnDependencies);
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;
}),
];
return res;
}
return [op];
});

View File

@@ -13,7 +13,7 @@ const dialect = {
explicitDropConstraint: false,
enableConstraintsPerTable: true,
dropColumnDependencies: ['default', 'dependencies', 'indexes', 'primaryKey', 'foreignKeys', 'uniques'],
changeColumnDependencies: ['indexes'],
changeColumnDependencies: ['indexes', 'dependencies', 'uniques'],
anonymousPrimaryKey: false,
dropIndexContainsTableSpec: true,
quoteIdentifier(s) {