Browse Source

fix: remove relations in a logical order from meta on base delete

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/4918/head
mertmit 2 years ago
parent
commit
33340b5f74
  1. 51
      packages/nocodb/src/lib/models/Base.ts

51
packages/nocodb/src/lib/models/Base.ts

@ -7,7 +7,7 @@ import {
MetaTable, MetaTable,
} from '../utils/globals'; } from '../utils/globals';
import Model from './Model'; import Model from './Model';
import { BaseType } from 'nocodb-sdk'; import { BaseType, UITypes } from 'nocodb-sdk';
import NocoCache from '../cache/NocoCache'; import NocoCache from '../cache/NocoCache';
import CryptoJS from 'crypto-js'; import CryptoJS from 'crypto-js';
import { extractProps } from '../meta/helpers/extractProps'; import { extractProps } from '../meta/helpers/extractProps';
@ -277,6 +277,55 @@ export default class Base implements BaseType {
}, },
ncMeta ncMeta
); );
const relColumns = [];
const relRank = {
[UITypes.Lookup]: 1,
[UITypes.Rollup]: 2,
[UITypes.ForeignKey]: 3,
[UITypes.LinkToAnotherRecord]: 4,
}
for (const model of models) {
for (const col of await model.getColumns(ncMeta)) {
let colOptionTableName = null;
let cacheScopeName = null;
switch (col.uidt) {
case UITypes.Rollup:
colOptionTableName = MetaTable.COL_ROLLUP;
cacheScopeName = CacheScope.COL_ROLLUP;
break;
case UITypes.Lookup:
colOptionTableName = MetaTable.COL_LOOKUP;
cacheScopeName = CacheScope.COL_LOOKUP;
break;
case UITypes.ForeignKey:
case UITypes.LinkToAnotherRecord:
colOptionTableName = MetaTable.COL_RELATIONS;
cacheScopeName = CacheScope.COL_RELATION;
break;
}
if (colOptionTableName && cacheScopeName) {
relColumns.push({ col, colOptionTableName, cacheScopeName });
}
}
}
relColumns.sort((a, b) => {
return relRank[a.col.uidt] - relRank[b.col.uidt];
});
for (const relCol of relColumns) {
await ncMeta.metaDelete(null, null, relCol.colOptionTableName, {
fk_column_id: relCol.col.id,
});
await NocoCache.deepDel(
relCol.cacheScopeName,
`${relCol.cacheScopeName}:${relCol.col.id}`,
CacheDelDirection.CHILD_TO_PARENT
);
}
for (const model of models) { for (const model of models) {
await model.delete(ncMeta, true); await model.delete(ncMeta, true);
} }

Loading…
Cancel
Save