mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 04:23:57 +00:00
preloadedRows insert only implementation
This commit is contained in:
@@ -606,7 +606,7 @@ export class SqlDumper implements AlterProcessor {
|
|||||||
this.putCmd('^drop %s %f', this.getSqlObjectSqlName(obj.objectTypeField), obj);
|
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;
|
let was = false;
|
||||||
for (const row of newRows) {
|
for (const row of newRows) {
|
||||||
const old = oldRows?.find(r => key.every(col => r[col] == row[col]));
|
const old = oldRows?.find(r => key.every(col => r[col] == row[col]));
|
||||||
@@ -614,7 +614,7 @@ export class SqlDumper implements AlterProcessor {
|
|||||||
if (old) {
|
if (old) {
|
||||||
const updated = [];
|
const updated = [];
|
||||||
for (const col of rowKeys) {
|
for (const col of rowKeys) {
|
||||||
if (row[col] != old[col]) {
|
if (row[col] != old[col] && !insertOnly?.includes(col)) {
|
||||||
updated.push(col);
|
updated.push(col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ interface AlterOperation_FillPreloadedRows {
|
|||||||
oldRows: any[];
|
oldRows: any[];
|
||||||
newRows: any[];
|
newRows: any[];
|
||||||
key: string[];
|
key: string[];
|
||||||
|
insertOnly: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
type AlterOperation =
|
type AlterOperation =
|
||||||
@@ -232,13 +233,14 @@ export class AlterPlan {
|
|||||||
this.recreates.tables += 1;
|
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({
|
this.operations.push({
|
||||||
operationType: 'fillPreloadedRows',
|
operationType: 'fillPreloadedRows',
|
||||||
table,
|
table,
|
||||||
oldRows,
|
oldRows,
|
||||||
newRows,
|
newRows,
|
||||||
key,
|
key,
|
||||||
|
insertOnly,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -565,7 +567,7 @@ export function runAlterOperation(op: AlterOperation, processor: AlterProcessor)
|
|||||||
processor.dropSqlObject(op.oldObject);
|
processor.dropSqlObject(op.oldObject);
|
||||||
break;
|
break;
|
||||||
case 'fillPreloadedRows':
|
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;
|
break;
|
||||||
case 'recreateTable':
|
case 'recreateTable':
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -116,9 +116,10 @@ export class DatabaseInfoAlterProcessor {
|
|||||||
throw new Error('recreateTable not implemented for 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);
|
const tableInfo = this.db.tables.find(x => x.pureName == table.pureName && x.schemaName == table.schemaName);
|
||||||
tableInfo.preloadedRows = newRows;
|
tableInfo.preloadedRows = newRows;
|
||||||
tableInfo.preloadedRowsKey = key;
|
tableInfo.preloadedRowsKey = key;
|
||||||
|
tableInfo.preloadedRowsInsertOnly = insertOnly;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ function createPairs(oldList, newList, additionalCondition = null) {
|
|||||||
function planTablePreload(plan: AlterPlan, oldTable: TableInfo, newTable: TableInfo) {
|
function planTablePreload(plan: AlterPlan, oldTable: TableInfo, newTable: TableInfo) {
|
||||||
const key = newTable.preloadedRowsKey || newTable.primaryKey?.columns?.map(x => x.columnName);
|
const key = newTable.preloadedRowsKey || newTable.primaryKey?.columns?.map(x => x.columnName);
|
||||||
if (newTable.preloadedRows?.length > 0 && key?.length > 0) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ export interface TableInfoYaml {
|
|||||||
primaryKey?: string[];
|
primaryKey?: string[];
|
||||||
|
|
||||||
insertKey?: string[];
|
insertKey?: string[];
|
||||||
|
insertOnly?: string[];
|
||||||
data?: any[];
|
data?: any[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,6 +125,7 @@ export function tableInfoFromYaml(table: TableInfoYaml, allTables: TableInfoYaml
|
|||||||
}
|
}
|
||||||
res.preloadedRows = table.data;
|
res.preloadedRows = table.data;
|
||||||
res.preloadedRowsKey = table.insertKey;
|
res.preloadedRowsKey = table.insertKey;
|
||||||
|
res.preloadedRowsInsertOnly = table.insertOnly;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
packages/types/alter-processor.d.ts
vendored
2
packages/types/alter-processor.d.ts
vendored
@@ -15,5 +15,5 @@ export interface AlterProcessor {
|
|||||||
recreateTable(oldTable: TableInfo, newTable: TableInfo);
|
recreateTable(oldTable: TableInfo, newTable: TableInfo);
|
||||||
createSqlObject(obj: SqlObjectInfo);
|
createSqlObject(obj: SqlObjectInfo);
|
||||||
dropSqlObject(obj: SqlObjectInfo);
|
dropSqlObject(obj: SqlObjectInfo);
|
||||||
fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[]);
|
fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[]);
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/types/dbinfo.d.ts
vendored
1
packages/types/dbinfo.d.ts
vendored
@@ -80,6 +80,7 @@ export interface TableInfo extends DatabaseObjectInfo {
|
|||||||
checks?: CheckInfo[];
|
checks?: CheckInfo[];
|
||||||
preloadedRows?: any[];
|
preloadedRows?: any[];
|
||||||
preloadedRowsKey?: string[];
|
preloadedRowsKey?: string[];
|
||||||
|
preloadedRowsInsertOnly?: string[];
|
||||||
__isDynamicStructure?: boolean;
|
__isDynamicStructure?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user