From 152572b1661aecb86c0ae2b996f3514040925520 Mon Sep 17 00:00:00 2001 From: Pranav C <61551451+pranavxc@users.noreply.github.com> Date: Tue, 6 Jul 2021 11:11:42 +0530 Subject: [PATCH] fix: handle old project migration Signed-off-by: Pranav C <61551451+pranavxc@users.noreply.github.com> --- packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts b/packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts index bfe357e517..f6ed35fc27 100644 --- a/packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts +++ b/packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts @@ -688,9 +688,10 @@ export default abstract class BaseApiBuilder implements XcDynami // update version in meta after each upgrade config.version = version.name; - await this.xcMeta.metaInsert(this.projectId, this.dbAlias, 'nc_store', { - key: 'NC_CONFIG', + await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_store', { value: JSON.stringify(config) + }, { + key: 'NC_CONFIG', }); // todo: backup data @@ -710,11 +711,15 @@ export default abstract class BaseApiBuilder implements XcDynami this.baseLog(`xcUpgrade : Inserting config to meta database`,) const configObj: NcConfig = JSON.parse(JSON.stringify(this.config)); delete configObj.envs; - configObj.version = process.env.NC_VERSION; + const isOld = (await this.xcMeta.metaList(this.projectId, this.dbAlias, 'nc_models'))?.length; + configObj.version = isOld ? '0009000' : process.env.NC_VERSION; await this.xcMeta.metaInsert(this.projectId, this.dbAlias, 'nc_store', { key: 'NC_CONFIG', value: JSON.stringify(configObj) }); + if (isOld) { + await this.xcUpgrade(); + } } }