Browse Source

feat(nocodb): ncFilterUpgrader_0105003

pull/5185/head
Wing-Kam Wong 2 years ago
parent
commit
dd87298750
  1. 2
      packages/nocodb/src/lib/version-upgrader/NcUpgrader.ts
  2. 38
      packages/nocodb/src/lib/version-upgrader/ncFilterUpgrader_0105003.ts

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

@ -13,6 +13,7 @@ import ncAttachmentUpgrader from './ncAttachmentUpgrader';
import ncAttachmentUpgrader_0104002 from './ncAttachmentUpgrader_0104002'; import ncAttachmentUpgrader_0104002 from './ncAttachmentUpgrader_0104002';
import ncStickyColumnUpgrader from './ncStickyColumnUpgrader'; import ncStickyColumnUpgrader from './ncStickyColumnUpgrader';
import ncFilterUpgrader_0104004 from './ncFilterUpgrader_0104004'; import ncFilterUpgrader_0104004 from './ncFilterUpgrader_0104004';
import ncFilterUpgrader_0105003 from './ncFilterUpgrader_0105003';
const log = debug('nc:version-upgrader'); const log = debug('nc:version-upgrader');
import boxen from 'boxen'; import boxen from 'boxen';
@ -45,6 +46,7 @@ export default class NcUpgrader {
{ name: '0104002', handler: ncAttachmentUpgrader_0104002 }, { name: '0104002', handler: ncAttachmentUpgrader_0104002 },
{ name: '0104004', handler: ncFilterUpgrader_0104004 }, { name: '0104004', handler: ncFilterUpgrader_0104004 },
{ name: '0105002', handler: ncStickyColumnUpgrader }, { name: '0105002', handler: ncStickyColumnUpgrader },
{ name: '0105003', handler: ncFilterUpgrader_0105003 },
]; ];
if (!(await ctx.ncMeta.knexConnection?.schema?.hasTable?.('nc_store'))) { if (!(await ctx.ncMeta.knexConnection?.schema?.hasTable?.('nc_store'))) {
return; return;

38
packages/nocodb/src/lib/version-upgrader/ncFilterUpgrader_0105003.ts

@ -0,0 +1,38 @@
import { NcUpgraderCtx } from './NcUpgrader';
import { MetaTable } from '../utils/globals';
import NcMetaIO from '../meta/NcMetaIO';
import Column from '../models/Column';
import Filter from '../models/Filter';
import { UITypes } from 'nocodb-sdk';
// as of 0.105.3, date / datetime filters include `is like` and `is not like` which are not practical
// this upgrader is simply to remove them
// Change Summary:
// - Date / DateTime columns: remove `is like` and `is not like`
const removeLikeFilters = (filter, ncMeta) => {
let actions = [];
// remove `is like` and `is not like`
if (['like', 'nlike'].includes(filter.comparison_op)) {
actions.push(Filter.delete(filter.id, ncMeta));
}
return actions;
};
async function removeFilters(ncMeta: NcMetaIO) {
const filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP);
for (const filter of filters) {
if (!filter.fk_column_id || filter.is_group) {
continue;
}
const col = await Column.get({ colId: filter.fk_column_id }, ncMeta);
if ([UITypes.Date, UITypes.DateTime].includes(col.uidt)) {
await Promise.all(removeLikeFilters(filter, ncMeta));
}
}
}
export default async function ({ ncMeta }: NcUpgraderCtx) {
await removeFilters(ncMeta);
}
Loading…
Cancel
Save