mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 20:06:00 +00:00
preloaded rows works with autoinc columns (fix for mssql)
This commit is contained in:
@@ -210,7 +210,6 @@ export class SqlDumper implements AlterProcessor {
|
|||||||
} else {
|
} else {
|
||||||
this.putRaw(SqlDumper.convertKeywordCase(type));
|
this.putRaw(SqlDumper.convertKeywordCase(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
columnDefinition(column: ColumnInfo, { includeDefault = true, includeNullable = true, includeCollate = true } = {}) {
|
columnDefinition(column: ColumnInfo, { includeDefault = true, includeNullable = true, includeCollate = true } = {}) {
|
||||||
@@ -653,7 +652,14 @@ 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[], insertOnly: string[]) {
|
fillPreloadedRows(
|
||||||
|
table: NamedObjectInfo,
|
||||||
|
oldRows: any[],
|
||||||
|
newRows: any[],
|
||||||
|
key: string[],
|
||||||
|
insertOnly: string[],
|
||||||
|
autoIncrementColumn: 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]));
|
||||||
@@ -676,12 +682,15 @@ export class SqlDumper implements AlterProcessor {
|
|||||||
} else {
|
} else {
|
||||||
if (was) this.put(';\n');
|
if (was) this.put(';\n');
|
||||||
was = true;
|
was = true;
|
||||||
|
const autoinc = rowKeys.includes(autoIncrementColumn);
|
||||||
|
if (autoinc) this.allowIdentityInsert(table, true);
|
||||||
this.put(
|
this.put(
|
||||||
'^insert ^into %f (%,i) ^values (%,v)',
|
'^insert ^into %f (%,i) ^values (%,v)',
|
||||||
table,
|
table,
|
||||||
rowKeys,
|
rowKeys,
|
||||||
rowKeys.map(x => row[x])
|
rowKeys.map(x => row[x])
|
||||||
);
|
);
|
||||||
|
if (autoinc) this.allowIdentityInsert(table, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (was) {
|
if (was) {
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ interface AlterOperation_FillPreloadedRows {
|
|||||||
newRows: any[];
|
newRows: any[];
|
||||||
key: string[];
|
key: string[];
|
||||||
insertOnly: string[];
|
insertOnly: string[];
|
||||||
|
autoIncrementColumn: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type AlterOperation =
|
type AlterOperation =
|
||||||
@@ -233,7 +234,14 @@ export class AlterPlan {
|
|||||||
this.recreates.tables += 1;
|
this.recreates.tables += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[]) {
|
fillPreloadedRows(
|
||||||
|
table: NamedObjectInfo,
|
||||||
|
oldRows: any[],
|
||||||
|
newRows: any[],
|
||||||
|
key: string[],
|
||||||
|
insertOnly: string[],
|
||||||
|
autoIncrementColumn: string
|
||||||
|
) {
|
||||||
this.operations.push({
|
this.operations.push({
|
||||||
operationType: 'fillPreloadedRows',
|
operationType: 'fillPreloadedRows',
|
||||||
table,
|
table,
|
||||||
@@ -241,6 +249,7 @@ export class AlterPlan {
|
|||||||
newRows,
|
newRows,
|
||||||
key,
|
key,
|
||||||
insertOnly,
|
insertOnly,
|
||||||
|
autoIncrementColumn,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -567,7 +576,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, op.insertOnly);
|
processor.fillPreloadedRows(op.table, op.oldRows, op.newRows, op.key, op.insertOnly, op.autoIncrementColumn);
|
||||||
break;
|
break;
|
||||||
case 'recreateTable':
|
case 'recreateTable':
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -116,7 +116,14 @@ 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[], insertOnly: string[]) {
|
fillPreloadedRows(
|
||||||
|
table: NamedObjectInfo,
|
||||||
|
oldRows: any[],
|
||||||
|
newRows: any[],
|
||||||
|
key: string[],
|
||||||
|
insertOnly: string[],
|
||||||
|
autoIncrementColumn: 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;
|
||||||
|
|||||||
@@ -368,7 +368,8 @@ function planTablePreload(plan: AlterPlan, oldTable: TableInfo, newTable: TableI
|
|||||||
oldTable?.preloadedRows,
|
oldTable?.preloadedRows,
|
||||||
newTable.preloadedRows,
|
newTable.preloadedRows,
|
||||||
key,
|
key,
|
||||||
newTable.preloadedRowsInsertOnly
|
newTable.preloadedRowsInsertOnly,
|
||||||
|
newTable.columns.find(x => x.autoIncrement)?.columnName
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9
packages/types/alter-processor.d.ts
vendored
9
packages/types/alter-processor.d.ts
vendored
@@ -15,5 +15,12 @@ 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[], insertOnly: string[]);
|
fillPreloadedRows(
|
||||||
|
table: NamedObjectInfo,
|
||||||
|
oldRows: any[],
|
||||||
|
newRows: any[],
|
||||||
|
key: string[],
|
||||||
|
insertOnly: string[],
|
||||||
|
autoIncrementColumn: string
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user