From da0e1cf815d6658d1d1969ca572ed0f87d5e84e1 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 27 Apr 2023 13:50:28 +0800 Subject: [PATCH] chore(nocodb): rollback old version to avoid confusion --- packages/nocodb/src/lib/meta/NcMetaIOImpl.ts | 33 ++++------------- .../nocodb/src/lib/utils/NcConfigFactory.ts | 35 ------------------- 2 files changed, 7 insertions(+), 61 deletions(-) diff --git a/packages/nocodb/src/lib/meta/NcMetaIOImpl.ts b/packages/nocodb/src/lib/meta/NcMetaIOImpl.ts index cf8d246b66..b04157a088 100644 --- a/packages/nocodb/src/lib/meta/NcMetaIOImpl.ts +++ b/packages/nocodb/src/lib/meta/NcMetaIOImpl.ts @@ -1,6 +1,5 @@ import CryptoJS from 'crypto-js'; import { customAlphabet } from 'nanoid'; -import dayjs from 'dayjs'; import { XKnex } from '../db/sql-data-mapper'; import XcMigrationSource from '../migrations/XcMigrationSource'; import NcConnectionMgr from '../utils/common/NcConnectionMgr'; @@ -95,20 +94,6 @@ export default class NcMetaIOImpl extends NcMetaIO { return (this.trx || this.connection) as any; } - private isMySQL(): boolean { - return ( - this.config?.meta?.db?.client === 'mysql' || - this.config?.meta?.db?.client === 'mysql2' - ); - } - - private now(): any { - if (this.isMySQL()) { - return dayjs().utc().format('YYYY-MM-DD HH:mm:ss'); - } - return dayjs().utc().toISOString(); - } - public updateKnex(connectionConfig): void { this.connection = XKnex(connectionConfig); } @@ -122,10 +107,6 @@ export default class NcMetaIOImpl extends NcMetaIO { migrationSource: new XcMigrationSourcev2(), tableName: 'xc_knex_migrationsv2', }); - if (this.isMySQL()) { - // set timezone - await this.connection.raw(`SET time_zone = '+00:00'`); - } return true; } @@ -257,9 +238,9 @@ export default class NcMetaIOImpl extends NcMetaIO { return this.knexConnection(target).insert({ db_alias: dbAlias, project_id, + created_at: this.knexConnection?.fn?.now(), + updated_at: this.knexConnection?.fn?.now(), ...data, - created_at: this.now(), - updated_at: this.now(), }); } @@ -279,8 +260,8 @@ export default class NcMetaIOImpl extends NcMetaIO { if (project_id !== null) insertObj.project_id = project_id; await this.knexConnection(target).insert({ ...insertObj, - created_at: this.now(), - updated_at: this.now(), + created_at: insertObj?.created_at || this.knexConnection?.fn?.now(), + updated_at: insertObj?.updated_at || this.knexConnection?.fn?.now(), }); return insertObj; } @@ -429,7 +410,7 @@ export default class NcMetaIOImpl extends NcMetaIO { delete data.created_at; - query.update({ ...data, updated_at: this.now() }); + query.update({ ...data, updated_at: this.knexConnection?.fn?.now() }); if (typeof idOrCondition !== 'object') { query.where('id', idOrCondition); } else if (idOrCondition) { @@ -549,8 +530,8 @@ export default class NcMetaIOImpl extends NcMetaIO { // todo: check project name used or not await this.knexConnection('nc_projects').insert({ ...project, - created_at: this.now(), - updated_at: this.now(), + created_at: this.knexConnection?.fn?.now(), + updated_at: this.knexConnection?.fn?.now(), }); // todo diff --git a/packages/nocodb/src/lib/utils/NcConfigFactory.ts b/packages/nocodb/src/lib/utils/NcConfigFactory.ts index f521585e92..85c1fe1d7c 100644 --- a/packages/nocodb/src/lib/utils/NcConfigFactory.ts +++ b/packages/nocodb/src/lib/utils/NcConfigFactory.ts @@ -232,13 +232,6 @@ export default class NcConfigFactory implements NcConfig { acquireConnectionTimeout: 600000, } as any; - if (url.protocol.startsWith('mysql')) { - dbConfig.connection = { - ...dbConfig.connection, - ...this.mysqlConnectionTypeCastConfig, - }; - } - if (process.env.NODE_TLS_REJECT_UNAUTHORIZED) { dbConfig.connection.ssl = true; } @@ -351,14 +344,6 @@ export default class NcConfigFactory implements NcConfig { } : {}), }; - - if (url.protocol.startsWith('mysql')) { - dbConfig.connection = { - ...dbConfig.connection, - ...this.mysqlConnectionTypeCastConfig, - }; - } - if (process.env.NODE_TLS_REJECT_UNAUTHORIZED) { dbConfig.connection.ssl = true; } @@ -521,13 +506,6 @@ export default class NcConfigFactory implements NcConfig { }, }; } - - if (dbConfig.client.startsWith('mysql')) { - dbConfig.connection = { - ...dbConfig.connection, - ...this.mysqlConnectionTypeCastConfig, - }; - } // todo: const key = ''; @@ -761,19 +739,6 @@ export default class NcConfigFactory implements NcConfig { return res; } - private static mysqlConnectionTypeCastConfig = { - typeCast: function (field, next) { - if ( - field.type === 'DATETIME' && - (field.name === 'created_at' || field.name === 'updated_at') - ) { - return new Date(field.string() + ' UTC'); - } - return next(); - }, - timezone: '+00:00', - }; - // public static initOneClickDeployment() { // if (process.env.NC_ONE_CLICK) { // const url = NcConfigFactory.extractXcUrlFromJdbc(process.env.DATABASE_URL);