delete part of restore script

This commit is contained in:
SPRINX0\prochazka
2025-12-01 12:07:44 +01:00
parent 8ae64a9dcf
commit b912190c5e

View File

@@ -1,5 +1,5 @@
import _, { cond } from 'lodash';
import { Condition, dumpSqlInsert, dumpSqlUpdate, Insert, Update } from 'dbgate-sqltree';
import _ from 'lodash';
import { Condition, dumpSqlInsert, dumpSqlUpdate, Insert, Update, Delete, dumpSqlDelete } from 'dbgate-sqltree';
import { TableInfo, SqlDumper } from 'dbgate-types';
export function createTableRestoreScript(backupTable: TableInfo, originalTable: TableInfo, dmp: SqlDumper) {
@@ -74,6 +74,25 @@ export function createTableRestoreScript(backupTable: TableInfo, originalTable:
dumpSqlUpdate(dmp, update);
dmp.endCommand();
const delcmd: Delete = {
commandType: 'delete',
from: { name: originalTable },
where: {
conditionType: 'notExists',
subQuery: {
commandType: 'select',
from: { name: backupTable, alias: 'bak' },
selectAll: true,
where: {
conditionType: 'and',
conditions: keyColumns.map(colName => makeColumnCond(colName)),
},
},
},
};
dumpSqlDelete(dmp, delcmd);
dmp.endCommand();
const insert: Insert = {
commandType: 'insert',
targetTable: originalTable,