drop table context menu

This commit is contained in:
Jan Prochazka
2021-09-10 20:08:17 +02:00
parent 37c305461f
commit 016e96d0e6
3 changed files with 93 additions and 3 deletions

View File

@@ -246,6 +246,16 @@ export class AlterPlan {
return res;
}
if (op.operationType == 'dropTable') {
return [
...(op.oldObject.dependencies || []).map(oldObject => ({
operationType: 'dropConstraint',
oldObject,
})),
op,
];
}
return [op];
});
@@ -371,6 +381,9 @@ export function runAlterOperation(op: AlterOperation, processor: AlterProcessor)
case 'dropColumn':
processor.dropColumn(op.oldObject);
break;
case 'dropTable':
processor.dropTable(op.oldObject);
break;
case 'changeConstraint':
processor.changeConstraint(op.oldObject, op.newObject);
break;

View File

@@ -285,6 +285,34 @@ export function createAlterTablePlan(
return plan;
}
export function createAlterDatabasePlan(
oldDb: DatabaseInfo,
newDb: DatabaseInfo,
opts: DbDiffOptions,
db: DatabaseInfo,
driver: EngineDriver
): AlterPlan {
const plan = new AlterPlan(db, driver.dialect);
for (const objectTypeField of ['tables']) {
for (const oldobj of oldDb[objectTypeField]) {
const newobj = newDb[objectTypeField].find(x => x.pairingId == oldobj.pairingId);
if (objectTypeField == 'tables') {
if (newobj == null) plan.dropTable(oldobj);
else planAlterTable(plan, oldobj, newobj, opts);
}
}
for (const newobj of newDb[objectTypeField]) {
const oldobj = oldDb[objectTypeField].find(x => x.pairingId == newobj.pairingId);
if (objectTypeField == 'tables') {
if (newobj == null) plan.createTable(newobj);
}
}
}
plan.transformPlan();
return plan;
}
export function getAlterTableScript(
oldTable: TableInfo,
newTable: TableInfo,
@@ -294,6 +322,19 @@ export function getAlterTableScript(
): string {
const plan = createAlterTablePlan(oldTable, newTable, opts, db, driver);
const dmp = driver.createDumper();
plan.run(dmp );
plan.run(dmp);
return dmp.s;
}
export function getAlterDatabaseScript(
oldDb: DatabaseInfo,
newDb: DatabaseInfo,
opts: DbDiffOptions,
db: DatabaseInfo,
driver: EngineDriver
): string {
const plan = createAlterDatabasePlan(oldDb, newDb, opts, db, driver);
const dmp = driver.createDumper();
plan.run(dmp);
return dmp.s;
}