Browse Source

feat(wip): back-end support for multiple base

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/3573/head
mertmit 2 years ago
parent
commit
3c2c7ef3ff
  1. 1
      packages/nocodb/src/lib/meta/api/dataApis/helpers.ts
  2. 1
      packages/nocodb/src/lib/meta/api/dataApis/oldDataApis.ts
  3. 10
      packages/nocodb/src/lib/meta/api/metaDiffApis.ts
  4. 4
      packages/nocodb/src/lib/meta/api/modelVisibilityApis.ts
  5. 10
      packages/nocodb/src/lib/meta/api/projectApis.ts
  6. 26
      packages/nocodb/src/lib/models/Model.ts

1
packages/nocodb/src/lib/meta/api/dataApis/helpers.ts

@ -24,7 +24,6 @@ export async function getViewAndModelFromRequestByAliasOrId(
const model = await Model.getByAliasOrId({
project_id: project.id,
base_id: project.bases?.[0]?.id,
aliasOrId: req.params.tableName,
});
const view =

1
packages/nocodb/src/lib/meta/api/dataApis/oldDataApis.ts

@ -108,7 +108,6 @@ async function getViewAndModelFromRequest(req) {
const project = await Project.getWithInfo(req.params.projectId);
const model = await Model.getByAliasOrId({
project_id: project.id,
base_id: project.bases?.[0]?.id,
aliasOrId: req.params.tableName,
});
const view =

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

@ -532,18 +532,19 @@ async function getMetaDiff(
export async function metaDiff(req, res) {
const project = await Project.getWithInfo(req.params.projectId);
const base = project.bases[0];
const changes = []
for (const base of project.bases) {
// @ts-ignore
const sqlClient = NcConnectionMgrv2.getSqlClient(base);
const changes = await getMetaDiff(sqlClient, project, base);
changes.push(await getMetaDiff(sqlClient, project, base));
}
res.json(changes);
}
export async function metaDiffSync(req, res) {
const project = await Project.getWithInfo(req.params.projectId);
const base = project.bases[0];
for (const base of project.bases) {
const virtualColumnInsert: Array<() => Promise<void>> = [];
// @ts-ignore
@ -728,6 +729,7 @@ export async function metaDiffSync(req, res) {
// populate m2m relations
await extractAndGenerateManyToManyRelations(await base.getModels());
}
Tele.emit('evt', { evt_type: 'metaDiff:synced' });

4
packages/nocodb/src/lib/meta/api/modelVisibilityApis.ts

@ -3,7 +3,6 @@ import ModelRoleVisibility from '../../models/ModelRoleVisibility';
import { Router } from 'express';
import { Tele } from 'nc-help';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import Project from '../../models/Project';
import { metaApiMetrics } from '../helpers/apiMetrics';
async function xcVisibilityMetaSetAll(req, res) {
Tele.emit('evt', { evt_type: 'uiAcl:updated' });
@ -49,13 +48,12 @@ export async function xcVisibilityMetaGet(
const roles = ['owner', 'creator', 'viewer', 'editor', 'commenter', 'guest'];
const defaultDisabled = roles.reduce((o, r) => ({ ...o, [r]: false }), {});
const project = await Project.getWithInfo(projectId);
let models =
_models ||
(await Model.list({
project_id: projectId,
base_id: project?.bases?.[0]?.id,
base_id: undefined,
}));
models = includeM2M ? models : (models.filter((t) => !t.mm) as Model[]);

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

@ -452,15 +452,12 @@ async function populateMeta(base: Base, project: Project): Promise<any> {
return info;
}
export async function projectInfoGet(req, res) {
const project = await Project.getWithInfo(req.params.projectId);
export async function projectInfoGet(_req, res) {
res.json({
Node: process.version,
Arch: process.arch,
Platform: process.platform,
Docker: isDocker(),
Database: project.bases?.[0]?.type,
ProjectOnRootDB: !!project?.is_meta,
RootDB: Noco.getConfig()?.meta?.db?.client,
PackageVersion: packageVersion,
});
@ -469,7 +466,9 @@ export async function projectInfoGet(req, res) {
export async function projectCost(req, res) {
let cost = 0;
const project = await Project.getWithInfo(req.params.projectId);
const sqlClient = NcConnectionMgrv2.getSqlClient(project.bases[0]);
for (const base of project.bases) {
const sqlClient = NcConnectionMgrv2.getSqlClient(base);
const userCount = await ProjectUser.getUsersCount(req.query);
const recordCount = (await sqlClient.totalRecords())?.data.TotalRecords;
@ -486,6 +485,7 @@ export async function projectCost(req, res) {
// $120/user/yr
cost = Math.min(120 * userCount, 36000);
}
}
Tele.event({
event: 'a:project:cost',

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

@ -597,7 +597,7 @@ export default class Model implements TableType {
aliasOrId,
}: {
project_id: string;
base_id: string | undefined;
base_id?: string;
aliasOrId: string;
},
ncMeta = Noco.ncMeta
@ -610,7 +610,8 @@ export default class Model implements TableType {
CacheGetType.TYPE_OBJECT
));
if (!modelId) {
const model = await ncMeta.metaGet2(
const model = base_id
? await ncMeta.metaGet2(
null,
null,
MetaTable.MODELS,
@ -630,6 +631,27 @@ export default class Model implements TableType {
},
],
}
)
: await ncMeta.metaGet2(
null,
null,
MetaTable.MODELS,
{ project_id },
null,
{
_or: [
{
id: {
eq: aliasOrId,
},
},
{
title: {
eq: aliasOrId,
},
},
],
}
);
if (model) {
await NocoCache.set(

Loading…
Cancel
Save