mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
data duplicator fix
This commit is contained in:
parent
1ab58a491a
commit
6b783027e5
@ -118,17 +118,28 @@ class DuplicatorItemHolder {
|
|||||||
skipped += 1;
|
skipped += 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await runCommandOnDriver(pool, driver, dmp =>
|
let res = await runQueryOnDriver(pool, driver, dmp => {
|
||||||
dmp.putCmd(
|
dmp.put(
|
||||||
'^insert ^into %f (%,i) ^values (%,v)',
|
'^insert ^into %f (%,i) ^values (%,v)',
|
||||||
this.table,
|
this.table,
|
||||||
Object.keys(insertedObj),
|
Object.keys(insertedObj),
|
||||||
Object.values(insertedObj)
|
Object.values(insertedObj)
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (
|
||||||
|
this.autoColumn &&
|
||||||
|
this.isReferenced &&
|
||||||
|
!this.duplicator.driver.dialect.requireStandaloneSelectForScopeIdentity
|
||||||
|
) {
|
||||||
|
dmp.selectScopeIdentity(this.table);
|
||||||
|
}
|
||||||
|
});
|
||||||
inserted += 1;
|
inserted += 1;
|
||||||
if (this.autoColumn && this.isReferenced) {
|
if (this.autoColumn && this.isReferenced) {
|
||||||
const res = await runQueryOnDriver(pool, driver, dmp => dmp.selectScopeIdentity(this.table));
|
if (this.duplicator.driver.dialect.requireStandaloneSelectForScopeIdentity) {
|
||||||
|
res = await runQueryOnDriver(pool, driver, dmp => dmp.selectScopeIdentity(this.table));
|
||||||
|
}
|
||||||
|
// console.log('IDRES', JSON.stringify(res));
|
||||||
const resId = Object.entries(res?.rows?.[0])?.[0]?.[1];
|
const resId = Object.entries(res?.rows?.[0])?.[0]?.[1];
|
||||||
if (resId != null) {
|
if (resId != null) {
|
||||||
this.idMap[chunk[this.autoColumn]] = resId;
|
this.idMap[chunk[this.autoColumn]] = resId;
|
||||||
|
@ -23,6 +23,7 @@ const dialect = {
|
|||||||
export async function runCommandOnDriver(pool, driver: EngineDriver, cmd: (dmp: SqlDumper) => void): Promise<void> {
|
export async function runCommandOnDriver(pool, driver: EngineDriver, cmd: (dmp: SqlDumper) => void): Promise<void> {
|
||||||
const dmp = driver.createDumper();
|
const dmp = driver.createDumper();
|
||||||
cmd(dmp as any);
|
cmd(dmp as any);
|
||||||
|
// console.log('CMD:', dmp.s);
|
||||||
await driver.query(pool, dmp.s, { discardResult: true });
|
await driver.query(pool, dmp.s, { discardResult: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,6 +34,7 @@ export async function runQueryOnDriver(
|
|||||||
): Promise<QueryResult> {
|
): Promise<QueryResult> {
|
||||||
const dmp = driver.createDumper();
|
const dmp = driver.createDumper();
|
||||||
cmd(dmp as any);
|
cmd(dmp as any);
|
||||||
|
// console.log('QUERY:', dmp.s);
|
||||||
return await driver.query(pool, dmp.s);
|
return await driver.query(pool, dmp.s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
packages/types/dialect.d.ts
vendored
1
packages/types/dialect.d.ts
vendored
@ -11,6 +11,7 @@ export interface SqlDialect {
|
|||||||
anonymousPrimaryKey?: boolean;
|
anonymousPrimaryKey?: boolean;
|
||||||
defaultSchemaName?: string;
|
defaultSchemaName?: string;
|
||||||
enableConstraintsPerTable?: boolean;
|
enableConstraintsPerTable?: boolean;
|
||||||
|
requireStandaloneSelectForScopeIdentity?: boolean;
|
||||||
|
|
||||||
dropColumnDependencies?: string[];
|
dropColumnDependencies?: string[];
|
||||||
changeColumnDependencies?: string[];
|
changeColumnDependencies?: string[];
|
||||||
|
@ -42,6 +42,7 @@ const dialect = {
|
|||||||
dropCheck: true,
|
dropCheck: true,
|
||||||
|
|
||||||
dropReferencesWhenDropTable: false,
|
dropReferencesWhenDropTable: false,
|
||||||
|
requireStandaloneSelectForScopeIdentity: true,
|
||||||
|
|
||||||
columnProperties: {
|
columnProperties: {
|
||||||
columnComment: true,
|
columnComment: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user