Browse Source

feat: multiple source back-end

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/3573/head
mertmit 2 years ago
parent
commit
2d462de412
  1. 40
      packages/nocodb-sdk/src/lib/Api.ts
  2. 32
      packages/nocodb/src/lib/meta/api/baseApis.ts
  3. 18
      packages/nocodb/src/lib/meta/helpers/syncMigration.ts

40
packages/nocodb-sdk/src/lib/Api.ts

@ -2010,6 +2010,46 @@ export class Api<
format: 'json',
...params,
}),
/**
* No description
*
* @tags Base
* @name MetaDiffSync
* @request POST:/api/v1/db/meta/projects/{projectId}/meta-diff/{baseId}
* @response `200` `any` OK
*/
metaDiffSync: (
projectId: string,
baseId: string,
params: RequestParams = {}
) =>
this.request<any, any>({
path: `/api/v1/db/meta/projects/${projectId}/meta-diff/${baseId}`,
method: 'POST',
format: 'json',
...params,
}),
/**
* No description
*
* @tags Base
* @name MetaDiffGet
* @request GET:/api/v1/db/meta/projects/{projectId}/meta-diff/{baseId}
* @response `200` `any` OK
*/
metaDiffGet: (
projectId: string,
baseId: string,
params: RequestParams = {}
) =>
this.request<any, any>({
path: `/api/v1/db/meta/projects/${projectId}/meta-diff/${baseId}`,
method: 'GET',
format: 'json',
...params,
}),
};
dbTable = {
/**

32
packages/nocodb/src/lib/meta/api/baseApis.ts

@ -1,8 +1,8 @@
import { Request, Response } from 'express';
import Project from '../../models/Project';
import { ModelTypes, ProjectListType, UITypes } from 'nocodb-sdk';
import { BaseListType, ModelTypes, ProjectListType, UITypes } from 'nocodb-sdk';
import { PagedResponseImpl } from '../helpers/PagedResponse';
import syncMigration from '../helpers/syncMigration';
import { syncBaseMigration } from '../helpers/syncMigration';
import { IGNORE_TABLES } from '../../utils/common/BaseApiBuilder';
import Column from '../../models/Column';
import Model from '../../models/Model';
@ -39,18 +39,19 @@ export async function baseUpdate(
export async function baseList(
req: Request<any, any, any>,
res: Response<ProjectListType>,
res: Response<BaseListType>,
next
) {
try {
const projects = await Project.list(req.query);
const bases = await Base.list({ projectId: req.params.projectId });
res // todo: pagination
.json(
new PagedResponseImpl(projects, {
count: projects.length,
limit: projects.length,
.json({
bases: new PagedResponseImpl(bases, {
count: bases.length,
limit: bases.length,
})
}
);
} catch (e) {
console.log(e);
@ -71,9 +72,14 @@ export async function baseDelete(
async function baseCreate(req: Request<any, any>, res) {
// type | base | projectId
const baseBody = req.body;
const base = await Base.createBase(baseBody);
const project = await base.getProject();
await syncMigration(project);
const project = await Project.getWithInfo(req.params.projectId);
const base = await Base.createBase({
...baseBody,
type: baseBody.config?.client,
projectId: project.id,
});
await syncBaseMigration(project, base);
const info = await populateMeta(base, project);
@ -120,12 +126,14 @@ async function populateMeta(base: Base, project: Project): Promise<any> {
return t;
});
/* filter based on prefix */
// TODO add base prefix
/* filter based on prefix
if (project?.prefix) {
tables = tables.filter((t) => {
return t?.tn?.startsWith(project?.prefix);
});
}
*/
info.tablesCount = tables.length;

18
packages/nocodb/src/lib/meta/helpers/syncMigration.ts

@ -1,5 +1,6 @@
import Migrator from '../../db/sql-migrator/lib/KnexMigratorv2';
import Project from '../../models/Project';
import Base from '../../models/Base';
export default async function syncMigration(project: Project): Promise<void> {
for (const base of await project.getBases()) {
@ -19,3 +20,20 @@ export default async function syncMigration(project: Project): Promise<void> {
}
}
}
export async function syncBaseMigration(project: Project, base: Base): Promise<void> {
try {
/* create sql-migrator */
const migrator = new Migrator(project);
await migrator.init(base);
/* sql-migrator : sync & up */
await migrator.sync(base);
await migrator.migrationsUp({ base });
} catch (e) {
console.log(e);
// throw e;
}
}

Loading…
Cancel
Save