mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 06:43:59 +00:00
undelete view
This commit is contained in:
@@ -70,7 +70,7 @@ function checkStructure(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function testDatabaseDeploy(engine, conn, driver, dbModelsYaml, options) {
|
async function testDatabaseDeploy(engine, conn, driver, dbModelsYaml, options) {
|
||||||
const { testEmptyLastScript, finalCheckAgainstModel, dbdiffOptionsExtra } = options || {};
|
const { testEmptyLastScript, finalCheckAgainstModel, dbdiffOptionsExtra, allowDropStatements } = options || {};
|
||||||
let index = 0;
|
let index = 0;
|
||||||
for (const loadedDbModel of dbModelsYaml) {
|
for (const loadedDbModel of dbModelsYaml) {
|
||||||
const { sql, isEmpty } = await generateDeploySql({
|
const { sql, isEmpty } = await generateDeploySql({
|
||||||
@@ -81,7 +81,9 @@ async function testDatabaseDeploy(engine, conn, driver, dbModelsYaml, options) {
|
|||||||
dbdiffOptionsExtra,
|
dbdiffOptionsExtra,
|
||||||
});
|
});
|
||||||
console.debug('Generated deploy script:', sql);
|
console.debug('Generated deploy script:', sql);
|
||||||
|
if (!allowDropStatements) {
|
||||||
expect(sql.toUpperCase().includes('DROP ')).toBeFalsy();
|
expect(sql.toUpperCase().includes('DROP ')).toBeFalsy();
|
||||||
|
}
|
||||||
|
|
||||||
console.log('dbModelsYaml.length', dbModelsYaml.length, index);
|
console.log('dbModelsYaml.length', dbModelsYaml.length, index);
|
||||||
if (testEmptyLastScript && index == dbModelsYaml.length - 1) {
|
if (testEmptyLastScript && index == dbModelsYaml.length - 1) {
|
||||||
@@ -561,7 +563,7 @@ describe('Deploy database', () => {
|
|||||||
deletedSqlObjectPrefix: '_deleted_',
|
deletedSqlObjectPrefix: '_deleted_',
|
||||||
},
|
},
|
||||||
disallowExtraObjects: true,
|
disallowExtraObjects: true,
|
||||||
finalCheckAgainstModel: [T1, V1],
|
allowDropStatements: true,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { DbDiffOptions, generateTablePairingId } from './diffTools';
|
import { DbDiffOptions, generateTablePairingId, hasDeletedPrefix } from './diffTools';
|
||||||
import {
|
import {
|
||||||
AlterProcessor,
|
AlterProcessor,
|
||||||
ColumnInfo,
|
ColumnInfo,
|
||||||
@@ -548,7 +548,13 @@ export class AlterPlan {
|
|||||||
if (this.opts.noDropTable && op.operationType == 'dropTable') return false;
|
if (this.opts.noDropTable && op.operationType == 'dropTable') return false;
|
||||||
if (this.opts.noDropTable && op.operationType == 'recreateTable') return false;
|
if (this.opts.noDropTable && op.operationType == 'recreateTable') return false;
|
||||||
if (this.opts.noDropConstraint && op.operationType == 'dropConstraint') return false;
|
if (this.opts.noDropConstraint && op.operationType == 'dropConstraint') return false;
|
||||||
if (this.opts.noDropSqlObject && op.operationType == 'dropSqlObject') return false;
|
if (
|
||||||
|
this.opts.noDropSqlObject &&
|
||||||
|
op.operationType == 'dropSqlObject' &&
|
||||||
|
// allow to drop previously deleted SQL objects
|
||||||
|
!hasDeletedPrefix(op.oldObject.pureName, this.opts, this.opts.deletedSqlObjectPrefix)
|
||||||
|
)
|
||||||
|
return false;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ function getNameWithoutDeletedPrefix(name: string, opts: DbDiffOptions, deletedP
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasDeletedPrefix(name: string, opts: DbDiffOptions, deletedPrefix?: string) {
|
export function hasDeletedPrefix(name: string, opts: DbDiffOptions, deletedPrefix?: string) {
|
||||||
if (deletedPrefix) {
|
if (deletedPrefix) {
|
||||||
if (opts.ignoreCase) {
|
if (opts.ignoreCase) {
|
||||||
return (name || '').toLowerCase().startsWith(deletedPrefix.toLowerCase());
|
return (name || '').toLowerCase().startsWith(deletedPrefix.toLowerCase());
|
||||||
@@ -636,11 +636,9 @@ export function createAlterDatabasePlan(
|
|||||||
} else if (!opts.noDropSqlObject) {
|
} else if (!opts.noDropSqlObject) {
|
||||||
plan.dropSqlObject(oldobj);
|
plan.dropSqlObject(oldobj);
|
||||||
}
|
}
|
||||||
} else if (!testEqualSqlObjects(oldobj.createSql, newobj.createSql, opts)) {
|
} else if (!testEqualSqlObjects(oldobj, newobj, opts)) {
|
||||||
plan.recreates.sqlObjects += 1;
|
plan.recreates.sqlObjects += 1;
|
||||||
if (!opts.noDropSqlObject) {
|
|
||||||
plan.dropSqlObject(oldobj);
|
plan.dropSqlObject(oldobj);
|
||||||
}
|
|
||||||
plan.createSqlObject(newobj);
|
plan.createSqlObject(newobj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user