Browse Source

fix: upgrader

pull/7304/head
Pranav C 10 months ago
parent
commit
cce5a3813c
  1. 12
      packages/nocodb/src/models/Column.ts
  2. 28
      packages/nocodb/src/version-upgrader/ncXcdbCreatedAndUpdatedTimeUpgrader.ts

12
packages/nocodb/src/models/Column.ts

@ -1170,13 +1170,17 @@ export default class Column<T = any> 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

28
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) });
}
}

Loading…
Cancel
Save