disabled grouping recreate table OPs

This commit is contained in:
Jan Prochazka
2025-12-08 16:41:55 +01:00
parent 1b5646f526
commit 52dce7dfd3

View File

@@ -91,8 +91,8 @@ interface AlterOperation_RenameConstraint {
} }
interface AlterOperation_RecreateTable { interface AlterOperation_RecreateTable {
operationType: 'recreateTable'; operationType: 'recreateTable';
table: TableInfo; oldTable: TableInfo;
operations: AlterOperation[]; newTable: TableInfo;
} }
interface AlterOperation_FillPreloadedRows { interface AlterOperation_FillPreloadedRows {
operationType: 'fillPreloadedRows'; operationType: 'fillPreloadedRows';
@@ -249,11 +249,11 @@ export class AlterPlan {
}); });
} }
recreateTable(table: TableInfo, operations: AlterOperation[]) { recreateTable(oldTable: TableInfo, newTable: TableInfo) {
this.operations.push({ this.operations.push({
operationType: 'recreateTable', operationType: 'recreateTable',
table, oldTable,
operations, newTable,
}); });
this.recreates.tables += 1; this.recreates.tables += 1;
} }
@@ -504,15 +504,19 @@ export class AlterPlan {
return []; return [];
} }
const table = this.wholeNewDb.tables.find( const oldTable = this.wholeOldDb.tables.find(
x => x.pureName == op[objectField].pureName && x.schemaName == op[objectField].schemaName
);
const newTable = this.wholeNewDb.tables.find(
x => x.pureName == op[objectField].pureName && x.schemaName == op[objectField].schemaName x => x.pureName == op[objectField].pureName && x.schemaName == op[objectField].schemaName
); );
this.recreates.tables += 1; this.recreates.tables += 1;
return [ return [
{ {
operationType: 'recreateTable', operationType: 'recreateTable',
table, oldTable,
operations: [op], newTable,
// operations: [op],
}, },
]; ];
} }
@@ -520,35 +524,38 @@ export class AlterPlan {
} }
_groupTableRecreations(): AlterOperation[] { _groupTableRecreations(): AlterOperation[] {
const res = []; return this.operations;
const recreates = {};
for (const op of this.operations) { // this is not implemented now
if (op.operationType == 'recreateTable' && op.table) { // const res = [];
const existingRecreate = recreates[`${op.table.schemaName}||${op.table.pureName}`]; // const recreates = {};
if (existingRecreate) { // for (const op of this.operations) {
existingRecreate.operations.push(...op.operations); // if (op.operationType == 'recreateTable' && op.table) {
} else { // const existingRecreate = recreates[`${op.table.schemaName}||${op.table.pureName}`];
const recreate = { // if (existingRecreate) {
...op, // existingRecreate.operations.push(...op.operations);
operations: [...op.operations], // } else {
}; // const recreate = {
res.push(recreate); // ...op,
recreates[`${op.table.schemaName}||${op.table.pureName}`] = recreate; // operations: [...op.operations],
} // };
} else { // res.push(recreate);
// @ts-ignore // recreates[`${op.table.schemaName}||${op.table.pureName}`] = recreate;
const oldObject: TableInfo = op.oldObject || op.object; // }
if (oldObject) { // } else {
const recreated = recreates[`${oldObject.schemaName}||${oldObject.pureName}`]; // // @ts-ignore
if (recreated) { // const oldObject: TableInfo = op.oldObject || op.object;
recreated.operations.push(op); // if (oldObject) {
continue; // const recreated = recreates[`${oldObject.schemaName}||${oldObject.pureName}`];
} // if (recreated) {
} // recreated.operations.push(op);
res.push(op); // continue;
} // }
} // }
return res; // res.push(op);
// }
// }
// return res;
} }
_moveForeignKeysToLast(): AlterOperation[] { _moveForeignKeysToLast(): AlterOperation[] {
@@ -679,16 +686,16 @@ export function runAlterOperation(op: AlterOperation, processor: AlterProcessor)
break; break;
case 'recreateTable': case 'recreateTable':
{ {
const oldTable = generateTablePairingId(op.table); // const oldTable = generateTablePairingId(op.table);
const newTable = _.cloneDeep(oldTable); // const newTable = _.cloneDeep(oldTable);
const newDb = DatabaseAnalyser.createEmptyStructure(); // const newDb = DatabaseAnalyser.createEmptyStructure();
newDb.tables.push(newTable); // newDb.tables.push(newTable);
// console.log('////////////////////////////newTable1', newTable); // // console.log('////////////////////////////newTable1', newTable);
op.operations.forEach(child => runAlterOperation(child, new DatabaseInfoAlterProcessor(newDb))); // op.operations.forEach(child => runAlterOperation(child, new DatabaseInfoAlterProcessor(newDb)));
// console.log('////////////////////////////op.operations', op.operations); // // console.log('////////////////////////////op.operations', op.operations);
// console.log('////////////////////////////op.table', op.table); // // console.log('////////////////////////////op.table', op.table);
// console.log('////////////////////////////newTable2', newTable); // // console.log('////////////////////////////newTable2', newTable);
processor.recreateTable(oldTable, newTable); processor.recreateTable(op.oldTable, op.newTable);
} }
break; break;
} }