This commit is contained in:
Jan Prochazka
2020-09-27 08:28:59 +02:00
parent 5fa36c40f2
commit 154a4fc7d9
4 changed files with 13 additions and 2 deletions

View File

@@ -3,7 +3,7 @@ const driverConnect = require('../utility/driverConnect');
const engines = require('@dbgate/engines'); const engines = require('@dbgate/engines');
async function tableWriter({ connection, schemaName, pureName, ...options }) { async function tableWriter({ connection, schemaName, pureName, ...options }) {
console.log(`write table ${schemaName}.${pureName}`); console.log(`Write table ${schemaName}.${pureName}`);
const driver = engines(connection); const driver = engines(connection);
const pool = await driverConnect(driver, connection); const pool = await driverConnect(driver, connection);

View File

@@ -1,3 +1,4 @@
const { prepareTableForImport } = require('@dbgate/tools');
const _ = require('lodash'); const _ = require('lodash');
/** /**
@@ -34,7 +35,7 @@ function createBulkInsertStream(driver, mssql, stream, pool, name, options) {
if (options.createIfNotExists && (!structure || options.dropIfExists)) { if (options.createIfNotExists && (!structure || options.dropIfExists)) {
console.log(`Creating table ${fullName}`); console.log(`Creating table ${fullName}`);
const dmp = driver.createDumper(); const dmp = driver.createDumper();
dmp.createTable({ ...writable.structure, ...name }); dmp.createTable(prepareTableForImport({ ...writable.structure, ...name }));
console.log(dmp.s); console.log(dmp.s);
await driver.query(pool, dmp.s); await driver.query(pool, dmp.s);
structure = await driver.analyseSingleTable(pool, name); structure = await driver.analyseSingleTable(pool, name);

View File

@@ -1,2 +1,3 @@
export * from './commonTypeParser'; export * from './commonTypeParser';
export * from './nameTools'; export * from './nameTools';
export * from './tableTransforms';

View File

@@ -0,0 +1,9 @@
import { TableInfo } from '@dbgate/types';
import _ from 'lodash';
export function prepareTableForImport(table: TableInfo): TableInfo {
const res = _.cloneDeep(table);
res.foreignKeys = [];
if (res.primaryKey) res.primaryKey.constraintName = null;
return res;
}