preloadedRows insert only implementation

This commit is contained in:
Jan Prochazka
2021-12-09 18:26:10 +01:00
parent 7ad845d5c6
commit 1a0d5457ce
7 changed files with 13 additions and 7 deletions

View File

@@ -606,7 +606,7 @@ export class SqlDumper implements AlterProcessor {
this.putCmd('^drop %s %f', this.getSqlObjectSqlName(obj.objectTypeField), obj);
}
fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[]) {
fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[]) {
let was = false;
for (const row of newRows) {
const old = oldRows?.find(r => key.every(col => r[col] == row[col]));
@@ -614,7 +614,7 @@ export class SqlDumper implements AlterProcessor {
if (old) {
const updated = [];
for (const col of rowKeys) {
if (row[col] != old[col]) {
if (row[col] != old[col] && !insertOnly?.includes(col)) {
updated.push(col);
}
}

View File

@@ -93,6 +93,7 @@ interface AlterOperation_FillPreloadedRows {
oldRows: any[];
newRows: any[];
key: string[];
insertOnly: string[];
}
type AlterOperation =
@@ -232,13 +233,14 @@ export class AlterPlan {
this.recreates.tables += 1;
}
fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[]) {
fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[]) {
this.operations.push({
operationType: 'fillPreloadedRows',
table,
oldRows,
newRows,
key,
insertOnly,
});
}
@@ -565,7 +567,7 @@ export function runAlterOperation(op: AlterOperation, processor: AlterProcessor)
processor.dropSqlObject(op.oldObject);
break;
case 'fillPreloadedRows':
processor.fillPreloadedRows(op.table, op.oldRows, op.newRows, op.key);
processor.fillPreloadedRows(op.table, op.oldRows, op.newRows, op.key, op.insertOnly);
break;
case 'recreateTable':
{

View File

@@ -116,9 +116,10 @@ export class DatabaseInfoAlterProcessor {
throw new Error('recreateTable not implemented for DatabaseInfoAlterProcessor');
}
fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[]) {
fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[]) {
const tableInfo = this.db.tables.find(x => x.pureName == table.pureName && x.schemaName == table.schemaName);
tableInfo.preloadedRows = newRows;
tableInfo.preloadedRowsKey = key;
tableInfo.preloadedRowsInsertOnly = insertOnly;
}
}

View File

@@ -328,7 +328,7 @@ function createPairs(oldList, newList, additionalCondition = null) {
function planTablePreload(plan: AlterPlan, oldTable: TableInfo, newTable: TableInfo) {
const key = newTable.preloadedRowsKey || newTable.primaryKey?.columns?.map(x => x.columnName);
if (newTable.preloadedRows?.length > 0 && key?.length > 0) {
plan.fillPreloadedRows(newTable, oldTable?.preloadedRows, newTable.preloadedRows, key);
plan.fillPreloadedRows(newTable, oldTable?.preloadedRows, newTable.preloadedRows, key, newTable.preloadedRowsInsertOnly);
}
}

View File

@@ -24,6 +24,7 @@ export interface TableInfoYaml {
primaryKey?: string[];
insertKey?: string[];
insertOnly?: string[];
data?: any[];
}
@@ -124,6 +125,7 @@ export function tableInfoFromYaml(table: TableInfoYaml, allTables: TableInfoYaml
}
res.preloadedRows = table.data;
res.preloadedRowsKey = table.insertKey;
res.preloadedRowsInsertOnly = table.insertOnly;
return res;
}