From 2ce20b5facc4a8c9c41ac6e1b8039be0e8d6ee91 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Thu, 31 Oct 2024 12:35:32 +0100 Subject: [PATCH] mark view as deleted --- .../__tests__/deploy-database.spec.js | 97 ++++++++++++++++++- packages/tools/src/diffTools.ts | 2 +- 2 files changed, 97 insertions(+), 2 deletions(-) diff --git a/integration-tests/__tests__/deploy-database.spec.js b/integration-tests/__tests__/deploy-database.spec.js index 30065ba6..2144588b 100644 --- a/integration-tests/__tests__/deploy-database.spec.js +++ b/integration-tests/__tests__/deploy-database.spec.js @@ -53,6 +53,20 @@ function checkStructure( } } } + + for (const expectedView of expected.views) { + const realView = structure.views.find(x => x.pureName == expectedView.pureName); + expect(realView).toBeTruthy(); + } + + for (const realView of structure.views) { + const expectedView = expected.views.find(x => x.pureName == realView.pureName); + if (!expectedView) { + if (disallowExtraObjects) { + expect(realView).toBeFalsy(); + } + } + } } async function testDatabaseDeploy(engine, conn, driver, dbModelsYaml, options) { @@ -491,10 +505,91 @@ describe('Deploy database', () => { [], ], { - checkRenameDeletedObjects: true, dbdiffOptionsExtra: { allowTableMarkDropped: true, + allowSqlObjectMarkDropped: true, + allowColumnMarkDropped: true, }, + finalCheckAgainstModel: [ + { + name: 't1.table.yaml', + json: { + name: '_deleted_t1', + columns: [ + { name: 'id', type: 'int' }, + { name: 'val', type: 'int' }, + ], + primaryKey: ['id'], + }, + }, + ], + } + ); + }) + ); + + test.each(engines.map(engine => [engine.label, engine]))( + 'Mark view removed - %s', + testWrapper(async (conn, driver, engine) => { + await testDatabaseDeploy( + engine, + conn, + driver, + [ + [ + { + name: 't1.table.yaml', + json: { + name: 't1', + columns: [ + { name: 'id', type: 'int' }, + { name: 'val', type: 'int' }, + ], + primaryKey: ['id'], + }, + }, + { + name: 'v1.view.sql', + text: 'create view v1 as select * from t1', + }, + ], + [ + { + name: 't1.table.yaml', + json: { + name: 't1', + columns: [ + { name: 'id', type: 'int' }, + { name: 'val', type: 'int' }, + ], + primaryKey: ['id'], + }, + }, + ], + ], + { + dbdiffOptionsExtra: { + allowTableMarkDropped: true, + allowSqlObjectMarkDropped: true, + allowColumnMarkDropped: true, + }, + finalCheckAgainstModel: [ + { + name: 't1.table.yaml', + json: { + name: 't1', + columns: [ + { name: 'id', type: 'int' }, + { name: 'val', type: 'int' }, + ], + primaryKey: ['id'], + }, + }, + { + name: '_deleted_v1.view.sql', + text: 'create view v1 as select * from t1', + }, + ], } ); }) diff --git a/packages/tools/src/diffTools.ts b/packages/tools/src/diffTools.ts index fb38c35d..ce65a8d9 100644 --- a/packages/tools/src/diffTools.ts +++ b/packages/tools/src/diffTools.ts @@ -583,7 +583,7 @@ export function createAlterDatabasePlan( } } else { if (newobj == null) { - if (opts.allowSqlObjectMarkDropped) { + if (opts.allowSqlObjectMarkDropped && driver.dialect.renameSqlObject) { plan.renameSqlObject(oldobj, '_deleted_' + oldobj.pureName); } else if (!opts.noDropSqlObject) { plan.dropSqlObject(oldobj);