Browse Source

chore(nocodb): sync backend

pull/5601/head
Wing-Kam Wong 2 years ago
parent
commit
95e57083d2
  1. 34
      packages/nocodb-nest/src/meta/meta.service.ts
  2. 35
      packages/nocodb-nest/src/utils/NcConfigFactory.ts

34
packages/nocodb-nest/src/meta/meta.service.ts

@ -6,7 +6,7 @@ import {
OnModuleInit, OnModuleInit,
Optional, Optional,
} from '@nestjs/common'; } from '@nestjs/common';
import dayjs from 'dayjs';
import { customAlphabet } from 'nanoid'; import { customAlphabet } from 'nanoid';
import CryptoJS from 'crypto-js'; import CryptoJS from 'crypto-js';
import { Connection } from '../connection/connection'; import { Connection } from '../connection/connection';
@ -256,8 +256,8 @@ export class MetaService {
await this.knexConnection(target).insert({ await this.knexConnection(target).insert({
...insertObj, ...insertObj,
created_at: data?.created_at || this.knexConnection?.fn?.now(), created_at: this.now(),
updated_at: data?.updated_at || this.knexConnection?.fn?.now(), updated_at: this.now(),
}); });
return insertObj; return insertObj;
} }
@ -539,9 +539,9 @@ export class MetaService {
return this.knexConnection(target).insert({ return this.knexConnection(target).insert({
db_alias: dbAlias, db_alias: dbAlias,
project_id, project_id,
created_at: this.knexConnection?.fn?.now(),
updated_at: this.knexConnection?.fn?.now(),
...data, ...data,
created_at: this.now(),
updated_at: this.now(),
}); });
} }
@ -689,7 +689,7 @@ export class MetaService {
delete data.created_at; delete data.created_at;
query.update({ ...data, updated_at: this.knexConnection?.fn?.now() }); query.update({ ...data, updated_at: this.now() });
if (typeof idOrCondition !== 'object') { if (typeof idOrCondition !== 'object') {
query.where('id', idOrCondition); query.where('id', idOrCondition);
} else if (idOrCondition) { } else if (idOrCondition) {
@ -810,8 +810,8 @@ export class MetaService {
// todo: check project name used or not // todo: check project name used or not
await this.knexConnection('nc_projects').insert({ await this.knexConnection('nc_projects').insert({
...project, ...project,
created_at: this.knexConnection?.fn?.now(), created_at: this.now(),
updated_at: this.knexConnection?.fn?.now(), updated_at: this.now(),
}); });
// todo // todo
@ -1030,6 +1030,20 @@ export class MetaService {
return nanoid(); return nanoid();
} }
private isMySQL(): boolean {
return (
this.connection.clientType() === 'mysql' ||
this.connection.clientType() === 'mysql2'
);
}
private now(): any {
if (this.isMySQL()) {
return dayjs().utc().format('YYYY-MM-DD HH:mm:ss');
}
return dayjs().utc().toISOString();
}
public async audit( public async audit(
project_id: string, project_id: string,
dbAlias: string, dbAlias: string,
@ -1051,6 +1065,10 @@ export class MetaService {
migrationSource: new XcMigrationSourcev2(), migrationSource: new XcMigrationSourcev2(),
tableName: 'xc_knex_migrationsv2', tableName: 'xc_knex_migrationsv2',
}); });
if (this.isMySQL()) {
// set timezone
await this.connection.raw(`SET time_zone = '+00:00'`);
}
return true; return true;
} }
} }

35
packages/nocodb-nest/src/utils/NcConfigFactory.ts

@ -236,6 +236,13 @@ export default class NcConfigFactory {
acquireConnectionTimeout: 600000, acquireConnectionTimeout: 600000,
} as any; } as any;
if (url.protocol.startsWith('mysql')) {
dbConfig.connection = {
...dbConfig.connection,
...this.mysqlConnectionTypeCastConfig,
};
}
if (process.env.NODE_TLS_REJECT_UNAUTHORIZED) { if (process.env.NODE_TLS_REJECT_UNAUTHORIZED) {
dbConfig.connection.ssl = true; dbConfig.connection.ssl = true;
} }
@ -348,6 +355,14 @@ export default class NcConfigFactory {
} }
: {}), : {}),
}; };
if (url.protocol.startsWith('mysql')) {
dbConfig.connection = {
...dbConfig.connection,
...this.mysqlConnectionTypeCastConfig,
};
}
if (process.env.NODE_TLS_REJECT_UNAUTHORIZED) { if (process.env.NODE_TLS_REJECT_UNAUTHORIZED) {
dbConfig.connection.ssl = true; dbConfig.connection.ssl = true;
} }
@ -511,6 +526,13 @@ export default class NcConfigFactory {
}; };
} }
if (dbConfig.client.startsWith('mysql')) {
dbConfig.connection = {
...dbConfig.connection,
...this.mysqlConnectionTypeCastConfig,
};
}
// todo: // todo:
const key = ''; const key = '';
Object.assign(dbConfig, { Object.assign(dbConfig, {
@ -744,6 +766,19 @@ export default class NcConfigFactory {
return res; 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() { // public static initOneClickDeployment() {
// if (process.env.NC_ONE_CLICK) { // if (process.env.NC_ONE_CLICK) {
// const url = NcConfigFactory.extractXcUrlFromJdbc(process.env.DATABASE_URL); // const url = NcConfigFactory.extractXcUrlFromJdbc(process.env.DATABASE_URL);

Loading…
Cancel
Save