From 334440f6917094fa63f34d7b443c86ffc26dde97 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Fri, 13 Sep 2024 15:47:12 +0200 Subject: [PATCH] fixed import for clickhouse --- packages/tools/src/createBulkInsertStreamBase.ts | 3 ++- packages/tools/src/driverBase.ts | 4 ++++ packages/types/engines.d.ts | 2 ++ .../src/backend/createBulkInsertStream.js | 6 +----- .../dbgate-plugin-clickhouse/src/frontend/Dumper.js | 2 +- .../dbgate-plugin-clickhouse/src/frontend/driver.js | 10 ++++++++++ 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/tools/src/createBulkInsertStreamBase.ts b/packages/tools/src/createBulkInsertStreamBase.ts index eb16d9ff..dcf93e40 100644 --- a/packages/tools/src/createBulkInsertStreamBase.ts +++ b/packages/tools/src/createBulkInsertStreamBase.ts @@ -37,7 +37,8 @@ export function createBulkInsertStreamBase(driver: EngineDriver, stream, pool, n } if (options.createIfNotExists && (!structure || options.dropIfExists)) { const dmp = driver.createDumper(); - dmp.createTable(prepareTableForImport({ ...writable.structure, ...name })); + const createdTableInfo = driver.adaptTableInfo(prepareTableForImport({ ...writable.structure, ...name })); + dmp.createTable(createdTableInfo); logger.info({ sql: dmp.s }, `Creating table ${fullNameQuoted}`); await driver.script(pool, dmp.s); structure = await driver.analyseSingleTable(pool, name); diff --git a/packages/tools/src/driverBase.ts b/packages/tools/src/driverBase.ts index e67433fc..ebcf03cd 100644 --- a/packages/tools/src/driverBase.ts +++ b/packages/tools/src/driverBase.ts @@ -177,4 +177,8 @@ export const driverBase = { createSaveChangeSetScript(changeSet, dbinfo, defaultCreator) { return defaultCreator(changeSet, dbinfo); }, + + adaptTableInfo(table) { + return table; + } }; diff --git a/packages/types/engines.d.ts b/packages/types/engines.d.ts index 477bb784..1ee4b71a 100644 --- a/packages/types/engines.d.ts +++ b/packages/types/engines.d.ts @@ -228,6 +228,8 @@ export interface EngineDriver extends FilterBehaviourProvider { dbinfo: DatabaseInfo, defaultCreator: (changeSet: any, dbinfo: DatabaseInfo) => any ): any[]; + // adapts table info from different source (import, other database) to be suitable for this database + adaptTableInfo(table: TableInfo): TableInfo; analyserClass?: any; dumperClass?: any; diff --git a/plugins/dbgate-plugin-clickhouse/src/backend/createBulkInsertStream.js b/plugins/dbgate-plugin-clickhouse/src/backend/createBulkInsertStream.js index 4cf6f3ff..7627febf 100644 --- a/plugins/dbgate-plugin-clickhouse/src/backend/createBulkInsertStream.js +++ b/plugins/dbgate-plugin-clickhouse/src/backend/createBulkInsertStream.js @@ -6,11 +6,7 @@ const _ = require('lodash'); * @param {import('dbgate-types').EngineDriver} driver */ function createOracleBulkInsertStream(driver, stream, pool, name, options) { - const writable = createBulkInsertStreamBase(driver, stream, pool, name, { - ...options, - // this is really not used, send method below is used instead - commitAfterInsert: true, - }); + const writable = createBulkInsertStreamBase(driver, stream, pool, name, options); writable.send = async () => { await pool.insert({ diff --git a/plugins/dbgate-plugin-clickhouse/src/frontend/Dumper.js b/plugins/dbgate-plugin-clickhouse/src/frontend/Dumper.js index 77b3a05b..37c4332e 100644 --- a/plugins/dbgate-plugin-clickhouse/src/frontend/Dumper.js +++ b/plugins/dbgate-plugin-clickhouse/src/frontend/Dumper.js @@ -17,7 +17,7 @@ class Dumper extends SqlDumper { } columnType(dataType) { - this.putRaw(dataType); + this.putRaw(dataType || this.dialect.fallbackDataType); } renameColumn(column, newcol) { diff --git a/plugins/dbgate-plugin-clickhouse/src/frontend/driver.js b/plugins/dbgate-plugin-clickhouse/src/frontend/driver.js index bf97cb9c..390578cf 100644 --- a/plugins/dbgate-plugin-clickhouse/src/frontend/driver.js +++ b/plugins/dbgate-plugin-clickhouse/src/frontend/driver.js @@ -189,6 +189,16 @@ const driver = { useDatabaseUrl: 1, }; }, + + adaptTableInfo(table) { + if (!table.primaryKey && !table.sortingKey) { + return { + ...table, + tableEngine: 'Log', + }; + } + return table; + }, }; module.exports = driver;