From cce5a3813ca6d88ebafa7b3402a4fc2d126b1833 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 4 Jan 2024 13:19:27 +0000 Subject: [PATCH] fix: upgrader --- packages/nocodb/src/models/Column.ts | 12 +++++--- .../ncXcdbCreatedAndUpdatedTimeUpgrader.ts | 28 +++++++++++-------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/packages/nocodb/src/models/Column.ts b/packages/nocodb/src/models/Column.ts index 6b4b07805d..e3a003bc0f 100644 --- a/packages/nocodb/src/models/Column.ts +++ b/packages/nocodb/src/models/Column.ts @@ -1170,13 +1170,17 @@ export default class Column implements ColumnType { // whenever a new request comes for that formula, it will be populated again getFormulasReferredTheColumn({ column: updatedColumn, - columns: await Column.list({ fk_model_id: column.fk_model_id }), + columns: await Column.list({ fk_model_id: column.fk_model_id }, ncMeta), }) .then(async (formulas) => { for (const formula of formulas) { - await FormulaColumn.update(formula.id, { - parsed_tree: null, - }); + await FormulaColumn.update( + formula.id, + { + parsed_tree: null, + }, + ncMeta, + ); } }) // ignore the error and continue, if formula is no longer valid it will be captured in the next run diff --git a/packages/nocodb/src/version-upgrader/ncXcdbCreatedAndUpdatedTimeUpgrader.ts b/packages/nocodb/src/version-upgrader/ncXcdbCreatedAndUpdatedTimeUpgrader.ts index e508ea51eb..7cea9bcd84 100644 --- a/packages/nocodb/src/version-upgrader/ncXcdbCreatedAndUpdatedTimeUpgrader.ts +++ b/packages/nocodb/src/version-upgrader/ncXcdbCreatedAndUpdatedTimeUpgrader.ts @@ -3,7 +3,7 @@ import { Logger } from '@nestjs/common'; import type { NcUpgraderCtx } from './NcUpgrader'; import type { MetaService } from '~/meta/meta.service'; import { MetaTable } from '~/utils/globals'; -import { Column, Model } from '~/models'; +import { Column, Model, Source } from '~/models'; import { getUniqueColumnAliasName, getUniqueColumnName, @@ -56,6 +56,8 @@ async function upgradeModels({ await Promise.all( models.map(async (model: any) => { + if (model.mm) return; + const columns = await model.getColumns(ncMeta); const oldColumns = columns.map((c) => ({ ...c, cn: c.column_name })); let isCreatedTimeExists = false; @@ -67,6 +69,7 @@ async function upgradeModels({ await Column.update( column.id, { + ...column, uidt: UITypes.CreatedTime, system: true, }, @@ -135,20 +138,23 @@ async function upgradeModels({ ...model, tn: model.table_name, originalColumns: oldColumns, - columns: [ - ...columns.map((c) => ({ ...c, cn: c.column_name })), - ...newColumns, - ], + columns: [...columns, ...newColumns].map((c) => ({ + ...c, + cn: c.column_name, + })), }; const sqlMgr = ProjectMgrv2.getSqlMgr({ id: source.base_id }, ncMeta); await sqlMgr.sqlOpPlus(source, 'tableUpdate', tableUpdateBody); for (const newColumn of newColumns) { - await Column.insert({ - ...newColumn, - system: 1, - fk_model_id: model.id, - }); + await Column.insert( + { + ...newColumn, + system: 1, + fk_model_id: model.id, + }, + ncMeta, + ); } } @@ -181,6 +187,6 @@ export default async function ({ ncMeta }: NcUpgraderCtx) { for (const source of sources) { logger.log(`Upgrading source ${source.name}`); // update the meta props - await upgradeModels({ ncMeta, source }); + await upgradeModels({ ncMeta, source: new Source(source) }); } }