diff --git a/integration-tests/__tests__/alter-processor.spec.js b/integration-tests/__tests__/alter-processor.spec.js index 4fd2b2bf8..ffc1d0e7b 100644 --- a/integration-tests/__tests__/alter-processor.spec.js +++ b/integration-tests/__tests__/alter-processor.spec.js @@ -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]))); diff --git a/packages/tools/src/alterPlan.ts b/packages/tools/src/alterPlan.ts index c409344df..b3f05de93 100644 --- a/packages/tools/src/alterPlan.ts +++ b/packages/tools/src/alterPlan.ts @@ -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]; }); diff --git a/plugins/dbgate-plugin-mssql/src/frontend/driver.js b/plugins/dbgate-plugin-mssql/src/frontend/driver.js index 608228abb..7626e4ec5 100644 --- a/plugins/dbgate-plugin-mssql/src/frontend/driver.js +++ b/plugins/dbgate-plugin-mssql/src/frontend/driver.js @@ -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) {