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,
Optional,
} from '@nestjs/common';
import dayjs from 'dayjs';
import { customAlphabet } from 'nanoid';
import CryptoJS from 'crypto-js';
import { Connection } from '../connection/connection';
@ -256,8 +256,8 @@ export class MetaService {
await this.knexConnection(target).insert({
...insertObj,
created_at: data?.created_at || this.knexConnection?.fn?.now(),
updated_at: data?.updated_at || this.knexConnection?.fn?.now(),
created_at: this.now(),
updated_at: this.now(),
});
return insertObj;
}
@ -539,9 +539,9 @@ export class MetaService {
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(),
});
}
@ -689,7 +689,7 @@ export class MetaService {
delete data.created_at;
query.update({ ...data, updated_at: this.knexConnection?.fn?.now() });
query.update({ ...data, updated_at: this.now() });
if (typeof idOrCondition !== 'object') {
query.where('id', idOrCondition);
} else if (idOrCondition) {
@ -810,8 +810,8 @@ export class MetaService {
// todo: check project name used or not
await this.knexConnection('nc_projects').insert({
...project,
created_at: this.knexConnection?.fn?.now(),
updated_at: this.knexConnection?.fn?.now(),
created_at: this.now(),
updated_at: this.now(),
});
// todo
@ -1030,6 +1030,20 @@ export class MetaService {
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(
project_id: string,
dbAlias: string,
@ -1051,6 +1065,10 @@ export class MetaService {
migrationSource: new XcMigrationSourcev2(),
tableName: 'xc_knex_migrationsv2',
});
if (this.isMySQL()) {
// set timezone
await this.connection.raw(`SET time_zone = '+00:00'`);
}
return true;
}
}

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

@ -236,6 +236,13 @@ export default class NcConfigFactory {
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;
}
@ -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) {
dbConfig.connection.ssl = true;
}
@ -511,6 +526,13 @@ export default class NcConfigFactory {
};
}
if (dbConfig.client.startsWith('mysql')) {
dbConfig.connection = {
...dbConfig.connection,
...this.mysqlConnectionTypeCastConfig,
};
}
// todo:
const key = '';
Object.assign(dbConfig, {
@ -744,6 +766,19 @@ export default class NcConfigFactory {
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);

Loading…
Cancel
Save