From 329725390646c2636a0902eb79adb4dd9e311804 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sat, 27 Nov 2021 18:10:34 +0100 Subject: [PATCH] deploy - update fixed data works in test --- .../__tests__/deploy-database.spec.js | 47 +++++++++++++++++++ integration-tests/engines.js | 4 +- packages/api/src/shell/generateDeploySql.js | 11 ++--- packages/tools/src/SqlDumper.ts | 2 +- packages/tools/src/preloadedRowsTools.ts | 4 +- 5 files changed, 56 insertions(+), 12 deletions(-) diff --git a/integration-tests/__tests__/deploy-database.spec.js b/integration-tests/__tests__/deploy-database.spec.js index d3c109bf..8b41b322 100644 --- a/integration-tests/__tests__/deploy-database.spec.js +++ b/integration-tests/__tests__/deploy-database.spec.js @@ -250,4 +250,51 @@ describe('Deploy database', () => { expect(res.rows[0].cnt.toString()).toEqual('3'); }) ); + + test.each(engines.map(engine => [engine.label, engine]))( + 'Deploy preloaded data - update - %s', + testWrapper(async (conn, driver, engine) => { + await testDatabaseDeploy(conn, driver, [ + [ + { + name: 't1.table.yaml', + json: { + name: 't1', + columns: [ + { name: 'id', type: 'int' }, + { name: 'val', type: 'int' }, + ], + primaryKey: ['id'], + data: [ + { id: 1, val: 1 }, + { id: 2, val: 2 }, + { id: 3, val: 3 }, + ], + }, + }, + ], + [ + { + name: 't1.table.yaml', + json: { + name: 't1', + columns: [ + { name: 'id', type: 'int' }, + { name: 'val', type: 'int' }, + ], + primaryKey: ['id'], + data: [ + { id: 1, val: 1 }, + { id: 2, val: 5 }, + { id: 3, val: 3 }, + ], + }, + }, + ], + ]); + + const res = await driver.query(conn, `select val from t1 where id = 2`); + expect(res.rows[0].val.toString()).toEqual('5'); + }) + ); }); diff --git a/integration-tests/engines.js b/integration-tests/engines.js index f73f0c98..ed1bcaf0 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 2364b119..4056428f 100644 --- a/packages/api/src/shell/generateDeploySql.js +++ b/packages/api/src/shell/generateDeploySql.js @@ -41,17 +41,14 @@ async function generateDeploySql({ noRenameColumn: true, }; const currentModelPaired = matchPairedObjects(deployedModel, currentModel, opts); - const currentModelPairedPreloaded = await enrichWithPreloadedRows( - deployedModel, - currentModelPaired, - pool, - driver - ); + const currentModelPairedPreloaded = await enrichWithPreloadedRows(deployedModel, currentModelPaired, pool, driver); + + // console.log('currentModelPairedPreloaded', currentModelPairedPreloaded.tables[0]); // console.log('deployedModel', deployedModel.tables[0]); // console.log('currentModel', currentModel.tables[0]); // console.log('currentModelPaired', currentModelPaired.tables[0]); const res = getAlterDatabaseScript( - currentModelPaired, + currentModelPairedPreloaded, deployedModel, opts, currentModelPairedPreloaded, diff --git a/packages/tools/src/SqlDumper.ts b/packages/tools/src/SqlDumper.ts index 88427a2b..65d327c1 100644 --- a/packages/tools/src/SqlDumper.ts +++ b/packages/tools/src/SqlDumper.ts @@ -623,7 +623,7 @@ export class SqlDumper implements AlterProcessor { was = true; this.put('^update %f ^set ', table); this.putCollection(', ', updated, col => this.put('%i=%v', col, row[col])); - this.put(' ^ where '); + this.put(' ^where '); this.putCollection(' ^and ', key, col => this.put('%i=%v', col, row[col])); } } else { diff --git a/packages/tools/src/preloadedRowsTools.ts b/packages/tools/src/preloadedRowsTools.ts index 882bc8a9..39e77705 100644 --- a/packages/tools/src/preloadedRowsTools.ts +++ b/packages/tools/src/preloadedRowsTools.ts @@ -11,9 +11,9 @@ export async function enrichWithPreloadedRows( const repl = {}; for (const tableTarget of dbTarget.tables) { const tableModel = dbModel.tables.find(x => x.pairingId == tableTarget.pairingId); - if (tableModel.preloadedRows?.length || 0 == 0) continue; + if ((tableModel.preloadedRows?.length || 0) == 0) continue; const keyColumns = tableModel.preloadedRowsKey || tableModel.primaryKey?.columns?.map(x => x.columnName); - if (keyColumns?.length || 0 == 0) continue; + if ((keyColumns?.length || 0) == 0) continue; const dmp = driver.createDumper(); if (keyColumns.length == 1) { dmp.putCmd(