Browse Source

feat(nocodb): ncFilterUpgrader

pull/4795/head
Wing-Kam Wong 2 years ago
parent
commit
554ef9c50d
  1. 2
      packages/nocodb/src/lib/Noco.ts
  2. 2
      packages/nocodb/src/lib/version-upgrader/NcUpgrader.ts
  3. 34
      packages/nocodb/src/lib/version-upgrader/ncFilterUpgrader.ts

2
packages/nocodb/src/lib/Noco.ts

@ -104,7 +104,7 @@ export default class Noco {
constructor() { constructor() {
process.env.PORT = process.env.PORT || '8080'; process.env.PORT = process.env.PORT || '8080';
// todo: move // todo: move
process.env.NC_VERSION = '0098005'; process.env.NC_VERSION = '0100002';
// if env variable NC_MINIMAL_DBS is set, then disable project creation with external sources // if env variable NC_MINIMAL_DBS is set, then disable project creation with external sources
if (process.env.NC_MINIMAL_DBS) { if (process.env.NC_MINIMAL_DBS) {

2
packages/nocodb/src/lib/version-upgrader/NcUpgrader.ts

@ -8,6 +8,7 @@ import ncProjectEnvUpgrader0011045 from './ncProjectEnvUpgrader0011045';
import ncProjectUpgraderV2_0090000 from './ncProjectUpgraderV2_0090000'; import ncProjectUpgraderV2_0090000 from './ncProjectUpgraderV2_0090000';
import ncDataTypesUpgrader from './ncDataTypesUpgrader'; import ncDataTypesUpgrader from './ncDataTypesUpgrader';
import ncProjectRolesUpgrader from './ncProjectRolesUpgrader'; import ncProjectRolesUpgrader from './ncProjectRolesUpgrader';
import ncFilterUpgrader from './ncFilterUpgrader';
const log = debug('nc:version-upgrader'); const log = debug('nc:version-upgrader');
import boxen from 'boxen'; import boxen from 'boxen';
@ -35,6 +36,7 @@ export default class NcUpgrader {
{ name: '0090000', handler: ncProjectUpgraderV2_0090000 }, { name: '0090000', handler: ncProjectUpgraderV2_0090000 },
{ name: '0098004', handler: ncDataTypesUpgrader }, { name: '0098004', handler: ncDataTypesUpgrader },
{ name: '0098005', handler: ncProjectRolesUpgrader }, { name: '0098005', handler: ncProjectRolesUpgrader },
{ name: '0100002', handler: ncFilterUpgrader },
]; ];
if (!(await ctx.ncMeta.knexConnection?.schema?.hasTable?.('nc_store'))) { if (!(await ctx.ncMeta.knexConnection?.schema?.hasTable?.('nc_store'))) {
return; return;

34
packages/nocodb/src/lib/version-upgrader/ncFilterUpgrader.ts

@ -0,0 +1,34 @@
import { NcUpgraderCtx } from './NcUpgrader';
import { MetaTable } from '../utils/globals';
import View from '../models/View';
import Hook from '../models/Hook';
import Column from '../models/Column';
// before 0.101.0, an incorrect project_id was inserted when
// a filter is created without specifying the column
// this upgrader is to retrieve the correct project id from either view, hook, or column
// and update the project id
export default async function ({ ncMeta }: NcUpgraderCtx) {
const filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP);
for (const filter of filters) {
let model: { project_id?: string; base_id?: string };
if (filter.fk_view_id) {
model = await View.get(filter.fk_view_id, ncMeta);
} else if (filter.fk_hook_id) {
model = await Hook.get(filter.fk_hook_id, ncMeta);
} else if (filter.fk_column_id) {
model = await Column.get({ colId: filter.fk_column_id }, ncMeta);
} else {
continue;
}
if (filter.project_id != model.project_id) {
await ncMeta.metaUpdate(
null,
null,
MetaTable.FILTER_EXP,
{ project_id: model.project_id },
filter.id
);
}
}
}
Loading…
Cancel
Save