|
|
|
@ -6,7 +6,8 @@ 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
|
|
|
|
|
// `removeFilters` in this upgrader is simply to remove them
|
|
|
|
|
// `removeLikeAndNlikeFilters` 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
|
|
|
|
@ -16,16 +17,8 @@ import { UITypes } from 'nocodb-sdk';
|
|
|
|
|
// - remove `is like` and `is not like`
|
|
|
|
|
// - add `exact date` in comparison_sub_op for existing filters `eq` and `neq`
|
|
|
|
|
|
|
|
|
|
const removeLikeFilters = (filter, ncMeta) => { |
|
|
|
|
async function removeLikeAndNlikeFilters(ncMeta: NcMetaIO) { |
|
|
|
|
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) { |
|
|
|
@ -33,9 +26,13 @@ async function removeFilters(ncMeta: NcMetaIO) {
|
|
|
|
|
} |
|
|
|
|
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)); |
|
|
|
|
// remove `is like` and `is not like`
|
|
|
|
|
if (['like', 'nlike'].includes(filter.comparison_op)) { |
|
|
|
|
actions.push(Filter.delete(filter.id, ncMeta)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
await Promise.all(actions); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async function migrateEqAndNeqFilters(ncMeta: NcMetaIO) { |
|
|
|
@ -59,6 +56,6 @@ async function migrateEqAndNeqFilters(ncMeta: NcMetaIO) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export default async function ({ ncMeta }: NcUpgraderCtx) { |
|
|
|
|
await removeFilters(ncMeta); |
|
|
|
|
await removeLikeAndNlikeFilters(ncMeta); |
|
|
|
|
await migrateEqAndNeqFilters(ncMeta); |
|
|
|
|
} |
|
|
|
|