From 57fdaf507376bee09315210176085f9172a22773 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Tue, 5 Oct 2021 21:52:04 +0200 Subject: [PATCH] deploy DB WIP --- .../__tests__/deploy-database.spec.js | 1 + integration-tests/engines.js | 4 +- packages/tools/src/diffTools.ts | 47 +++++++------------ 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/integration-tests/__tests__/deploy-database.spec.js b/integration-tests/__tests__/deploy-database.spec.js index b8a91e68..414f1aca 100644 --- a/integration-tests/__tests__/deploy-database.spec.js +++ b/integration-tests/__tests__/deploy-database.spec.js @@ -23,6 +23,7 @@ async function testDatabaseDeploy(conn, driver, dbModelsYaml) { driver, loadedDbModel, }); + console.debug('Generated deploy script:', sql); expect(sql.toUpperCase().includes('DROP ')).toBeFalsy(); await deployDb({ diff --git a/integration-tests/engines.js b/integration-tests/engines.js index ed1bcaf0..b50bfbf3 100644 --- a/integration-tests/engines.js +++ b/integration-tests/engines.js @@ -116,10 +116,10 @@ const engines = [ const filterLocal = [ // filter local testing - '-MySQL', + 'MySQL', '-PostgreSQL', '-SQL Server', - 'SQLite', + '-SQLite', '-CockroachDB', ]; diff --git a/packages/tools/src/diffTools.ts b/packages/tools/src/diffTools.ts index 1b252746..8a85bbf9 100644 --- a/packages/tools/src/diffTools.ts +++ b/packages/tools/src/diffTools.ts @@ -117,7 +117,7 @@ export function testEqualColumns( //} if (a.computedExpression != b.computedExpression) { console.debug( - `Column ${a.columnName}, ${b.columnName}: different computed expression: ${a.computedExpression}, ${b.computedExpression}` + `Column ${a.pureName}.${a.columnName}, ${b.pureName}.${b.columnName}: different computed expression: ${a.computedExpression}, ${b.computedExpression}` ); // opts.DiffLogger.Trace( // 'Column {0}, {1}: different computed expression: {2}; {3}', @@ -135,7 +135,7 @@ export function testEqualColumns( if (a.defaultValue == null) { if (a.defaultValue != b.defaultValue) { console.debug( - `Column ${a.columnName}, ${b.columnName}: different default value: ${a.defaultValue}, ${b.defaultValue}` + `Column ${a.pureName}.${a.columnName}, ${b.pureName}.${b.columnName}: different default value: ${a.defaultValue}, ${b.defaultValue}` ); // opts.DiffLogger.Trace( @@ -150,7 +150,7 @@ export function testEqualColumns( } else { if (a.defaultValue != b.defaultValue) { console.debug( - `Column ${a.columnName}, ${b.columnName}: different default value: ${a.defaultValue}, ${b.defaultValue}` + `Column ${a.pureName}.${a.columnName}, ${b.pureName}.${b.columnName}: different default value: ${a.defaultValue}, ${b.defaultValue}` ); // opts.DiffLogger.Trace( @@ -165,7 +165,7 @@ export function testEqualColumns( } if (a.defaultConstraint != b.defaultConstraint) { console.debug( - `Column ${a.columnName}, ${b.columnName}: different default constraint: ${a.defaultConstraint}, ${b.defaultConstraint}` + `Column ${a.pureName}.${a.columnName}, ${b.pureName}.${b.columnName}: different default constraint: ${a.defaultConstraint}, ${b.defaultConstraint}` ); // opts.DiffLogger.Trace( @@ -179,21 +179,25 @@ export function testEqualColumns( } } if ((a.notNull || false) != (b.notNull || false)) { - console.debug(`Column ${a.columnName}, ${b.columnName}: different nullability: ${a.notNull}, ${b.notNull}`); + console.debug( + `Column ${a.pureName}.${a.columnName}, ${b.pureName}.${b.columnName}: different nullability: ${a.notNull}, ${b.notNull}` + ); // opts.DiffLogger.Trace('Column {0}, {1}: different nullable: {2}; {3}', a, b, a.NotNull, b.NotNull); return false; } if ((a.autoIncrement || false) != (b.autoIncrement || false)) { console.debug( - `Column ${a.columnName}, ${b.columnName}: different autoincrement: ${a.autoIncrement}, ${b.autoIncrement}` + `Column ${a.pureName}.${a.columnName}, ${b.pureName}.${b.columnName}: different autoincrement: ${a.autoIncrement}, ${b.autoIncrement}` ); // opts.DiffLogger.Trace('Column {0}, {1}: different autoincrement: {2}; {3}', a, b, a.AutoIncrement, b.AutoIncrement); return false; } if ((a.isSparse || false) != (b.isSparse || false)) { - console.debug(`Column ${a.columnName}, ${b.columnName}: different is_sparse: ${a.isSparse}, ${b.isSparse}`); + console.debug( + `Column ${a.pureName}.${a.columnName}, ${b.pureName}.${b.columnName}: different is_sparse: ${a.isSparse}, ${b.isSparse}` + ); // opts.DiffLogger.Trace('Column {0}, {1}: different is_sparse: {2}; {3}', a, b, a.IsSparse, b.IsSparse); return false; @@ -232,35 +236,20 @@ export function testEqualColumns( } function testEqualConstraints(a: ConstraintInfo, b: ConstraintInfo, opts: DbDiffOptions = {}) { + if (a.constraintType=='primaryKey' && b.constraintType=='primaryKey') { + + } return stableStringify(a) == stableStringify(b); } export function testEqualTypes(a: ColumnInfo, b: ColumnInfo, opts: DbDiffOptions = {}) { - if (a.dataType != b.dataType) { - console.debug(`Column ${a.columnName}, ${b.columnName}: different data type: ${a.dataType}, ${b.dataType}`); - - // opts.DiffLogger.Trace("Column {0}, {1}: different types: {2}; {3}", a, b, a.DataType, b.DataType); + 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}` + ); return false; } - //if (a.Length != b.Length) - //{ - // opts.DiffLogger.Trace("Column {0}, {1}: different lengths: {2}; {3}", a, b, a.Length, b.Length); - // return false; - //} - - //if (a.Precision != b.Precision) - //{ - // opts.DiffLogger.Trace("Column {0}, {1}: different lengths: {2}; {3}", a, b, a.Precision, b.Precision); - // return false; - //} - - //if (a.Scale != b.Scale) - //{ - // opts.DiffLogger.Trace("Column {0}, {1}: different scale: {2}; {3}", a, b, a.Scale, b.Scale); - // return false; - //} - return true; }