mark view as deleted

This commit is contained in:
Jan Prochazka 2024-10-31 12:35:32 +01:00
parent 81297383cb
commit 2ce20b5fac
2 changed files with 97 additions and 2 deletions

View File

@ -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',
},
],
}
);
})

View File

@ -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);