Browse Source

feat: meta-diff apis for multiple base

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/3573/head
mertmit 2 years ago
parent
commit
1b369417d3
  1. 10
      packages/nocodb/src/lib/meta/api/metaDiffApis.ts
  2. 13
      packages/nocodb/src/lib/models/Model.ts

10
packages/nocodb/src/lib/meta/api/metaDiffApis.ts

@ -120,7 +120,7 @@ async function getMetaDiff(
const tableList: Array<{ tn: string }> = (
await sqlClient.tableList()
)?.data?.list?.filter((t) => {
if (project?.prefix) {
if (project?.prefix && base.is_meta) {
return t.tn?.startsWith(project?.prefix);
}
return true;
@ -417,7 +417,7 @@ async function getMetaDiff(
return v;
})
.filter((t) => {
if (project?.prefix) {
if (project?.prefix && base.is_meta) {
return t.tn?.startsWith(project?.prefix);
}
return true;
@ -532,11 +532,11 @@ async function getMetaDiff(
export async function metaDiff(req, res) {
const project = await Project.getWithInfo(req.params.projectId);
const changes = []
let changes = []
for (const base of project.bases) {
// @ts-ignore
const sqlClient = NcConnectionMgrv2.getSqlClient(base);
changes.push(await getMetaDiff(sqlClient, project, base));
changes = changes.concat(await getMetaDiff(sqlClient, project, base));
}
res.json(changes);
@ -576,7 +576,7 @@ export async function metaDiffSync(req, res) {
const model = await Model.insert(project.id, base.id, {
table_name: table_name,
title: getTableNameAlias(table_name, project.prefix, base),
title: getTableNameAlias(table_name, base.is_meta ? project.prefix : '', base),
type: ModelTypes.TABLE,
});

13
packages/nocodb/src/lib/models/Model.ts

@ -157,7 +157,12 @@ export default class Model implements TableType {
},
ncMeta = Noco.ncMeta
): Promise<Model[]> {
let modelList = await NocoCache.getList(CacheScope.MODEL, [project_id]);
let modelList = [];
if (base_id) {
await NocoCache.getList(CacheScope.MODEL, [project_id, base_id]);
} else {
await NocoCache.getList(CacheScope.MODEL, [project_id]);
}
if (!modelList.length) {
modelList = await ncMeta.metaList2(
project_id,
@ -170,7 +175,11 @@ export default class Model implements TableType {
}
);
await NocoCache.setList(CacheScope.MODEL, [project_id], modelList);
if (base_id) {
await NocoCache.setList(CacheScope.MODEL, [project_id, base_id], modelList);
} else {
await NocoCache.setList(CacheScope.MODEL, [project_id], modelList);
}
}
modelList.sort(
(a, b) =>

Loading…
Cancel
Save