Browse Source

Merge pull request #5933 from nocodb/fix/LTAR-upgrader-bug

fix:  LTAR upgrader bug
pull/5940/head
Pranav C 1 year ago committed by GitHub
parent
commit
c07f114006
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      packages/nocodb/src/version-upgrader/ncXcdbLTARUpgrader.ts

20
packages/nocodb/src/version-upgrader/ncXcdbLTARUpgrader.ts

@ -31,6 +31,7 @@ async function upgradeModelRelations({
rtn: string; rtn: string;
cn: string; cn: string;
rcn: string; rcn: string;
cstn?: string;
}[]; }[];
}) { }) {
// Iterate over each column and upgrade LTAR // Iterate over each column and upgrade LTAR
@ -74,6 +75,7 @@ async function upgradeModelRelations({
childColumn: relation.cn, childColumn: relation.cn,
parentTable: relation.rtn, parentTable: relation.rtn,
childTable: relation.tn, childTable: relation.tn,
foreignKeyName: relation.cstn,
}); });
} }
@ -119,17 +121,14 @@ async function upgradeModelRelations({
async function upgradeBaseRelations({ async function upgradeBaseRelations({
ncMeta, ncMeta,
base, base,
relations,
}: { }: {
ncMeta: MetaService; ncMeta: MetaService;
base: any; base: any;
relations: any;
}) { }) {
// const sqlMgr = ProjectMgrv2.getSqlMgr({ id: base.project_id }, ncMeta);
const sqlClient = await NcConnectionMgrv2.getSqlClient(base, ncMeta.knex); const sqlClient = await NcConnectionMgrv2.getSqlClient(base, ncMeta.knex);
// get all relations
const relations = (await sqlClient.relationListAll())?.data?.list;
// get models for the base // get models for the base
const models = await ncMeta.metaList2(null, base.id, MetaTable.MODELS); const models = await ncMeta.metaList2(null, base.id, MetaTable.MODELS);
@ -154,11 +153,22 @@ export default async function ({ ncMeta }: NcUpgraderCtx) {
orderBy: {}, orderBy: {},
}); });
if (!bases.length) return;
const sqlClient = await NcConnectionMgrv2.getSqlClient(
new Base(bases[0]),
ncMeta.knex,
);
// get all relations
const relations = (await sqlClient.relationListAll())?.data?.list;
// iterate and upgrade each base // iterate and upgrade each base
for (const base of bases) { for (const base of bases) {
await upgradeBaseRelations({ await upgradeBaseRelations({
ncMeta, ncMeta,
base: new Base(base), base: new Base(base),
relations,
}); });
} }
} }

Loading…
Cancel
Save