Browse Source

feat(nocodb): add migrateEqAndNeqFilters

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

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

@ -6,10 +6,15 @@ 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
// `removeFilters` in this upgrader is simply to remove them
// since the upcoming version will introduce a set of new filters for date / datetime with a new `comparison_sub_op`
// `eq` and `neq` would become `is` / `is not` (comparison_op) + `exact date` (comparison_sub_op)
// `migrateEqAndNeqFilters` in this upgrader is to add `exact date` in comparison_sub_op
// Change Summary:
// - Date / DateTime columns: remove `is like` and `is not like`
// - Date / DateTime columns:
// - remove `is like` and `is not like`
// - add `exact date` in comparison_sub_op for existing filters `eq` and `neq`
const removeLikeFilters = (filter, ncMeta) => {
let actions = [];
@ -33,6 +38,27 @@ async function removeFilters(ncMeta: NcMetaIO) {
}
}
async function migrateEqAndNeqFilters(ncMeta: NcMetaIO) {
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 ||
!['eq', 'neq'].includes(filter.comparison_op)
) {
continue;
}
actions.push(
Filter.update(filter.id, {
comparison_sub_op: 'exact_date',
})
);
}
await Promise.all(actions);
}
export default async function ({ ncMeta }: NcUpgraderCtx) {
await removeFilters(ncMeta);
await migrateEqAndNeqFilters(ncMeta);
}

Loading…
Cancel
Save