This commit is contained in:
Jan Prochazka
2022-01-29 11:30:10 +01:00
parent 1c5a22a071
commit c89e3adb38
7 changed files with 146 additions and 24 deletions

View File

@@ -29,18 +29,18 @@ export function createBulkInsertStreamBase(driver, stream, pool, name, options):
// console.log('ANALYSING', name, structure);
if (structure && options.dropIfExists) {
console.log(`Dropping table ${fullNameQuoted}`);
await driver.query(pool, `DROP TABLE ${fullNameQuoted}`);
await driver.script(pool, `DROP TABLE ${fullNameQuoted}`);
}
if (options.createIfNotExists && (!structure || options.dropIfExists)) {
console.log(`Creating table ${fullNameQuoted}`);
const dmp = driver.createDumper();
dmp.createTable(prepareTableForImport({ ...writable.structure, ...name }));
console.log(dmp.s);
await driver.query(pool, dmp.s);
await driver.script(pool, dmp.s);
structure = await driver.analyseSingleTable(pool, name);
}
if (options.truncate) {
await driver.query(pool, `TRUNCATE TABLE ${fullNameQuoted}`);
await driver.script(pool, `TRUNCATE TABLE ${fullNameQuoted}`);
}
writable.columnNames = _intersection(

View File

@@ -4,6 +4,9 @@ import _cloneDeep from 'lodash/cloneDeep';
export function prepareTableForImport(table: TableInfo): TableInfo {
const res = _cloneDeep(table);
res.foreignKeys = [];
res.indexes = [];
res.uniques = [];
res.checks = [];
if (res.primaryKey) res.primaryKey.constraintName = null;
return res;
}