undelete view

This commit is contained in:
Jan Prochazka
2024-10-31 15:01:01 +01:00
parent e5d4bbadc1
commit 9613c2c410
3 changed files with 17 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
import _ from 'lodash';
import { DbDiffOptions, generateTablePairingId } from './diffTools';
import { DbDiffOptions, generateTablePairingId, hasDeletedPrefix } from './diffTools';
import {
AlterProcessor,
ColumnInfo,
@@ -548,7 +548,13 @@ export class AlterPlan {
if (this.opts.noDropTable && op.operationType == 'dropTable') return false;
if (this.opts.noDropTable && op.operationType == 'recreateTable') 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;
});
}

View File

@@ -156,11 +156,11 @@ function getNameWithoutDeletedPrefix(name: string, opts: DbDiffOptions, deletedP
}
}
}
return name;
}
function hasDeletedPrefix(name: string, opts: DbDiffOptions, deletedPrefix?: string) {
export function hasDeletedPrefix(name: string, opts: DbDiffOptions, deletedPrefix?: string) {
if (deletedPrefix) {
if (opts.ignoreCase) {
return (name || '').toLowerCase().startsWith(deletedPrefix.toLowerCase());
@@ -636,11 +636,9 @@ export function createAlterDatabasePlan(
} else if (!opts.noDropSqlObject) {
plan.dropSqlObject(oldobj);
}
} else if (!testEqualSqlObjects(oldobj.createSql, newobj.createSql, opts)) {
} else if (!testEqualSqlObjects(oldobj, newobj, opts)) {
plan.recreates.sqlObjects += 1;
if (!opts.noDropSqlObject) {
plan.dropSqlObject(oldobj);
}
plan.dropSqlObject(oldobj);
plan.createSqlObject(newobj);
}
}