delete columns

This commit is contained in:
Jan Prochazka
2024-10-31 15:42:07 +01:00
parent 8ce4c0a7ce
commit 836d15c68f
2 changed files with 29 additions and 6 deletions

View File

@@ -504,7 +504,7 @@ describe('Deploy database', () => {
test.each(engines.filter(engine => engine.supportRenameSqlObject).map(engine => [engine.label, engine]))( test.each(engines.filter(engine => engine.supportRenameSqlObject).map(engine => [engine.label, engine]))(
'Mark view removed - %s', 'Mark view removed - %s',
testWrapper(async (conn, driver, engine) => { testWrapper(async (conn, driver, engine) => {
await testDatabaseDeploy(engine, conn, driver, [[T1, V1], [T1]], { await testDatabaseDeploy(engine, conn, driver, [[T1, V1], [T1], [T1]], {
markDeleted: true, markDeleted: true,
disallowExtraObjects: true, disallowExtraObjects: true,
finalCheckAgainstModel: [T1, V1_DELETED], finalCheckAgainstModel: [T1, V1_DELETED],
@@ -555,4 +555,14 @@ describe('Deploy database', () => {
}); });
}) })
); );
test.each(engines.map(engine => [engine.label, engine]))(
'Undelete column - %s',
testWrapper(async (conn, driver, engine) => {
await testDatabaseDeploy(engine, conn, driver, [[T1], [T1_NO_VAL], [T1]], {
markDeleted: true,
disallowExtraObjects: true,
});
})
);
}); });

View File

@@ -482,13 +482,24 @@ function planAlterTable(plan: AlterPlan, oldTable: TableInfo, newTable: TableInf
columnPairs columnPairs
.filter(x => x[0] && x[1]) .filter(x => x[0] && x[1])
.forEach(x => { .forEach(x => {
if (!testEqualColumns(x[0], x[1], true, true, opts)) { let srccol: ColumnInfo = x[0];
if (testEqualColumns(x[0], x[1], false, true, opts) && !opts.noRenameColumn) { let dstcol: ColumnInfo = x[1];
if (hasDeletedPrefix(srccol.columnName, opts, opts.deletedColumnPrefix)) {
plan.renameColumn(srccol, dstcol.columnName);
// rename is already done
srccol = {
...srccol,
columnName: dstcol.columnName,
};
}
if (!testEqualColumns(srccol, dstcol, true, true, opts)) {
if (testEqualColumns(srccol, dstcol, false, true, opts) && !opts.noRenameColumn) {
// console.log('PLAN RENAME COLUMN') // console.log('PLAN RENAME COLUMN')
plan.renameColumn(x[0], x[1].columnName); plan.renameColumn(srccol, dstcol.columnName);
} else { } else {
// console.log('PLAN CHANGE COLUMN', x[0], x[1]); // console.log('PLAN CHANGE COLUMN', x[0], x[1]);
plan.changeColumn(x[0], x[1]); plan.changeColumn(srccol, dstcol);
} }
} }
}); });
@@ -724,7 +735,9 @@ export function matchPairedObjects(db1: DatabaseInfo, db2: DatabaseInfo, opts: D
if (objectTypeField == 'tables') { if (objectTypeField == 'tables') {
for (const col2 of obj2.columns) { for (const col2 of obj2.columns) {
const col1 = obj1.columns.find(x => testEqualNames(x.columnName, col2.columnName, opts)); const col1 = obj1.columns.find(x =>
testEqualNames(x.columnName, col2.columnName, opts, opts.deletedColumnPrefix)
);
if (col1) col2.pairingId = col1.pairingId; if (col1) col2.pairingId = col1.pairingId;
} }