mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 20:43:58 +00:00
fixed importing mysql dump #702
This commit is contained in:
@@ -16,7 +16,7 @@ class ImportStream extends stream.Transform {
|
||||
}
|
||||
async _transform(chunk, encoding, cb) {
|
||||
try {
|
||||
await this.driver.script(this.pool, chunk);
|
||||
await this.driver.script(this.pool, chunk, { queryOptions: { importSqlDump: true } });
|
||||
} catch (err) {
|
||||
this.emit('error', err.message);
|
||||
}
|
||||
@@ -47,7 +47,9 @@ async function importDatabase({ connection = undefined, systemConnection = undef
|
||||
const pool = systemConnection || (await connectUtility(driver, connection, 'write'));
|
||||
logger.info(`Connected.`);
|
||||
|
||||
logger.info(`Input file: ${inputFile}`);
|
||||
const downloadedFile = await download(inputFile);
|
||||
logger.info(`Downloaded file: ${downloadedFile}`);
|
||||
|
||||
const fileStream = fs.createReadStream(downloadedFile, 'utf-8');
|
||||
const splittedStream = splitQueryStream(fileStream, driver.getQuerySplitterOptions('script'));
|
||||
|
||||
@@ -11,7 +11,7 @@ async function runScript(func) {
|
||||
await func();
|
||||
process.exit(0);
|
||||
} catch (err) {
|
||||
logger.error({ err }, `Error running script: ${err.message}`);
|
||||
logger.error({ err }, `Error running script: ${err.message || err}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ export const driverBase = {
|
||||
}
|
||||
for (const sqlItem of splitQuery(sql, this.getQuerySplitterOptions('script'))) {
|
||||
try {
|
||||
await this.query(pool, sqlItem, { discardResult: true });
|
||||
await this.query(pool, sqlItem, { discardResult: true, ...options?.queryOptions });
|
||||
} catch (err) {
|
||||
if (options?.useTransaction && this.supportsTransactions) {
|
||||
runCommandOnDriver(pool, this, dmp => dmp.rollbackTransaction());
|
||||
|
||||
2
packages/types/engines.d.ts
vendored
2
packages/types/engines.d.ts
vendored
@@ -25,10 +25,12 @@ export interface StreamOptions {
|
||||
|
||||
export interface RunScriptOptions {
|
||||
useTransaction: boolean;
|
||||
queryOptions?: QueryOptions;
|
||||
}
|
||||
|
||||
export interface QueryOptions {
|
||||
discardResult?: boolean;
|
||||
importSqlDump?: boolean;
|
||||
}
|
||||
|
||||
export interface WriteTableOptions {
|
||||
|
||||
Reference in New Issue
Block a user