From be1c1075b58f9ffd28d5500e2d5bc92609e103e0 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Thu, 14 Oct 2021 16:13:54 +0200 Subject: [PATCH] alter processor fixes --- integration-tests/engines.js | 4 ++-- packages/api/src/shell/generateDeploySql.js | 1 + packages/tools/src/alterPlan.ts | 15 +++++++++++++++ packages/tools/src/diffTools.ts | 6 ++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/integration-tests/engines.js b/integration-tests/engines.js index b50bfbf3..cb0401c7 100644 --- a/integration-tests/engines.js +++ b/integration-tests/engines.js @@ -116,8 +116,8 @@ const engines = [ const filterLocal = [ // filter local testing - 'MySQL', - '-PostgreSQL', + '-MySQL', + 'PostgreSQL', '-SQL Server', '-SQLite', '-CockroachDB', diff --git a/packages/api/src/shell/generateDeploySql.js b/packages/api/src/shell/generateDeploySql.js index 63d72ea0..2bcf7541 100644 --- a/packages/api/src/shell/generateDeploySql.js +++ b/packages/api/src/shell/generateDeploySql.js @@ -39,6 +39,7 @@ async function generateDeploySql({ noRenameTable: true, noRenameColumn: true, ignoreForeignKeyActions: true, + ignoreDataTypes: true, }; const currentModelPaired = matchPairedObjects(deployedModel, currentModel, opts); // console.log('deployedModel', deployedModel.tables[0]); diff --git a/packages/tools/src/alterPlan.ts b/packages/tools/src/alterPlan.ts index 2b4d965f..e915cac7 100644 --- a/packages/tools/src/alterPlan.ts +++ b/packages/tools/src/alterPlan.ts @@ -462,6 +462,17 @@ export class AlterPlan { ]; } + _filterAllowedOperations(): AlterOperation[] { + return this.operations.filter(op => { + if (this.opts.noDropColumn && op.operationType == 'dropColumn') return false; + if (this.opts.noDropTable && op.operationType == 'dropTable') return false; + if (this.opts.noDropTable && op.operationType == 'recreateTable') return false; + if (this.opts.noDropConstraint && op.operationType == 'dropConstraint') return false; + if (this.opts.noDropSqlObject && op.operationType == 'dropSqlObject') return false; + return true; + }); + } + transformPlan() { // console.log('*****************OPERATIONS0', this.operations); @@ -480,6 +491,10 @@ export class AlterPlan { this.operations = this._moveForeignKeysToLast(); // console.log('*****************OPERATIONS4', this.operations); + + this.operations = this._filterAllowedOperations(); + + // console.log('*****************OPERATIONS5', this.operations); } } diff --git a/packages/tools/src/diffTools.ts b/packages/tools/src/diffTools.ts index 707920f5..fd64a386 100644 --- a/packages/tools/src/diffTools.ts +++ b/packages/tools/src/diffTools.ts @@ -35,7 +35,9 @@ export interface DbDiffOptions { noDropSqlObject?: boolean; noRenameTable?: boolean; noRenameColumn?: boolean; + ignoreForeignKeyActions?: boolean; + ignoreDataTypes?: boolean; } export function generateTablePairingId(table: TableInfo): TableInfo { @@ -275,6 +277,10 @@ function testEqualConstraints(a: ConstraintInfo, b: ConstraintInfo, opts: DbDiff } export function testEqualTypes(a: ColumnInfo, b: ColumnInfo, opts: DbDiffOptions = {}) { + if (opts.ignoreDataTypes) { + return true; + } + if ((a.dataType || '').toLowerCase() != (b.dataType || '').toLowerCase()) { console.debug( `Column ${a.pureName}.${a.columnName}, ${b.pureName}.${b.columnName}: different data type: ${a.dataType}, ${b.dataType}`