Browse Source

refactor(nocodb): ncFilterUpgrader

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

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

@ -20,35 +20,19 @@ import { UITypes } from 'nocodb-sdk';
// - migrate `null` or `empty` filters to `blank` // - migrate `null` or `empty` filters to `blank`
// - add `exact date` in comparison_sub_op for existing filters `eq` and `neq` // - add `exact date` in comparison_sub_op for existing filters `eq` and `neq`
async function removeLikeAndNlikeFilters(ncMeta: NcMetaIO) { function removeLikeAndNlikeFilters(filter: Filter, ncMeta: NcMetaIO) {
let actions = []; let actions = [];
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)) {
// remove `is like` and `is not like` // remove `is like` and `is not like`
if (['like', 'nlike'].includes(filter.comparison_op)) { if (['like', 'nlike'].includes(filter.comparison_op)) {
actions.push(Filter.delete(filter.id, ncMeta)); actions.push(Filter.delete(filter.id, ncMeta));
} }
} return actions;
}
await Promise.all(actions);
} }
async function migrateEqAndNeqFilters(ncMeta: NcMetaIO) { function migrateEqAndNeqFilters(filter: Filter, ncMeta: NcMetaIO) {
let actions = []; let actions = [];
const filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP); // remove `is like` and `is not like`
for (const filter of filters) { if (['eq', 'neq'].includes(filter.comparison_op)) {
if (
!filter.fk_column_id ||
filter.is_group ||
!['eq', 'neq'].includes(filter.comparison_op)
) {
continue;
}
actions.push( actions.push(
Filter.update( Filter.update(
filter.id, filter.id,
@ -59,20 +43,12 @@ async function migrateEqAndNeqFilters(ncMeta: NcMetaIO) {
) )
); );
} }
await Promise.all(actions); return actions;
} }
async function migrateEmptyAndNullFilters(ncMeta: NcMetaIO) { function migrateEmptyAndNullFilters(filter: Filter, ncMeta: NcMetaIO) {
let actions = []; let actions = [];
const filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP); // remove `is like` and `is not like`
for (const filter of filters) {
if (
!filter.fk_column_id ||
filter.is_group ||
!['empty', 'notempty', 'null', 'notnull'].includes(filter.comparison_op)
) {
continue;
}
if (['empty', 'null'].includes(filter.comparison_op)) { if (['empty', 'null'].includes(filter.comparison_op)) {
// migrate to blank // migrate to blank
actions.push( actions.push(
@ -96,12 +72,22 @@ async function migrateEmptyAndNullFilters(ncMeta: NcMetaIO) {
) )
); );
} }
} return actions;
await Promise.all(actions);
} }
export default async function ({ ncMeta }: NcUpgraderCtx) { export default async function ({ ncMeta }: NcUpgraderCtx) {
await removeLikeAndNlikeFilters(ncMeta); const filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP);
await migrateEmptyAndNullFilters(ncMeta); for (const filter of filters) {
await migrateEqAndNeqFilters(ncMeta); 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([
...removeLikeAndNlikeFilters(filter, ncMeta),
...migrateEmptyAndNullFilters(filter, ncMeta),
...migrateEqAndNeqFilters(filter, ncMeta),
]);
}
}
} }

Loading…
Cancel
Save