Browse Source

refactor: getBases to getSources

pull/7202/head
mertmit 1 year ago
parent
commit
912f44f65a
  1. 2
      packages/nocodb/src/helpers/syncMigration.ts
  2. 17
      packages/nocodb/src/models/Base.ts
  3. 2
      packages/nocodb/src/models/BaseUser.ts
  4. 4
      packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.controller.ts
  5. 2
      packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts
  6. 2
      packages/nocodb/src/services/api-docs/swagger/getSwaggerColumnMetas.ts
  7. 2
      packages/nocodb/src/services/api-docs/swaggerV2/getSwaggerColumnMetas.ts
  8. 2
      packages/nocodb/src/services/bases.service.ts
  9. 2
      packages/nocodb/src/services/utils.service.ts
  10. 4
      packages/nocodb/tests/unit/factory/column.ts
  11. 2
      packages/nocodb/tests/unit/factory/row.ts
  12. 4
      packages/nocodb/tests/unit/factory/table.ts
  13. 2
      packages/nocodb/tests/unit/init/cleanupMeta.ts

2
packages/nocodb/src/helpers/syncMigration.ts

@ -2,7 +2,7 @@ import type { Base, Source } from '~/models';
import KnexMigratorv2 from '~/db/sql-migrator/lib/KnexMigratorv2';
export default async function syncMigration(base: Base): Promise<void> {
for (const source of await base.getBases()) {
for (const source of await base.getSources()) {
try {
/* create sql-migrator */
const migrator = new KnexMigratorv2(base);

17
packages/nocodb/src/models/Base.ts

@ -117,7 +117,7 @@ export default class Base implements BaseType {
);
const castedProjectList = baseList.map((m) => this.castType(m));
await Promise.all(castedProjectList.map((base) => base.getBases(ncMeta)));
await Promise.all(castedProjectList.map((base) => base.getSources(ncMeta)));
return castedProjectList;
}
@ -147,7 +147,7 @@ export default class Base implements BaseType {
return this.castType(baseData);
}
async getBases(ncMeta = Noco.ncMeta): Promise<Source[]> {
async getSources(ncMeta = Noco.ncMeta): Promise<Source[]> {
return (this.sources = await Source.list({ baseId: this.id }, ncMeta));
}
@ -182,10 +182,11 @@ export default class Base implements BaseType {
}
}
if (baseData) {
const base = new Base(baseData);
await base.getBases(ncMeta);
const base = this.castType(baseData);
return this.castType(base);
await base.getSources(ncMeta);
return base;
}
return null;
}
@ -359,7 +360,7 @@ export default class Base implements BaseType {
static async getWithInfoByTitle(title: string, ncMeta = Noco.ncMeta) {
const base = await this.getByTitle(title, ncMeta);
if (base) await base.getBases(ncMeta);
if (base) await base.getSources(ncMeta);
return base;
}
@ -441,7 +442,7 @@ export default class Base implements BaseType {
// parse meta
base.meta = parseMetaProp(base);
if (base) await base.getBases(ncMeta);
if (base) await base.getSources(ncMeta);
return base;
}
@ -449,7 +450,7 @@ export default class Base implements BaseType {
static async clearConnectionPool(baseId: string, ncMeta = Noco.ncMeta) {
const base = await this.get(baseId, ncMeta);
if (base) {
const sources = await base.getBases(ncMeta);
const sources = await base.getSources(ncMeta);
for (const source of sources) {
await NcConnectionMgrv2.deleteAwait(source);
}

2
packages/nocodb/src/models/BaseUser.ts

@ -381,7 +381,7 @@ export default class BaseUser {
.filter((p) => !params?.type || p.type === params.type)
.map((m) => Base.castType(m));
await Promise.all(castedProjectList.map((base) => base.getBases(ncMeta)));
await Promise.all(castedProjectList.map((base) => base.getSources(ncMeta)));
return castedProjectList;
}

4
packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.controller.ts

@ -53,7 +53,7 @@ export class DuplicateController {
throw new Error(`Base not found for id '${sharedBaseId}'`);
}
const source = (await base.getBases())[0];
const source = (await base.getSources())[0];
if (!source) {
throw new Error(`Source not found!`);
@ -124,7 +124,7 @@ export class DuplicateController {
const source = sourceId
? await Source.get(sourceId)
: (await base.getBases())[0];
: (await base.getSources())[0];
if (!source) {
throw new Error(`Source not found!`);

2
packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts

@ -74,7 +74,7 @@ export class DuplicateProcessor {
throw new Error(`Export failed for source '${source.id}'`);
}
await dupProject.getBases();
await dupProject.getSources();
const dupBase = dupProject.sources[0];

2
packages/nocodb/src/services/api-docs/swagger/getSwaggerColumnMetas.ts

@ -8,7 +8,7 @@ export default async (
base: Base,
ncMeta = Noco.ncMeta,
): Promise<SwaggerColumn[]> => {
const dbType = await base.getBases().then((b) => b?.[0]?.type);
const dbType = await base.getSources().then((b) => b?.[0]?.type);
return Promise.all(
columns.map(async (c) => {
const field: SwaggerColumn = {

2
packages/nocodb/src/services/api-docs/swaggerV2/getSwaggerColumnMetas.ts

@ -8,7 +8,7 @@ export default async (
base: Base,
ncMeta = Noco.ncMeta,
): Promise<SwaggerColumn[]> => {
const dbType = await base.getBases().then((b) => b?.[0]?.type);
const dbType = await base.getSources().then((b) => b?.[0]?.type);
return Promise.all(
columns.map(async (c) => {
const field: SwaggerColumn = {

2
packages/nocodb/src/services/bases.service.ts

@ -203,7 +203,7 @@ export class BasesService {
await syncMigration(base);
// populate metadata if existing table
for (const source of await base.getBases()) {
for (const source of await base.getSources()) {
if (process.env.NC_CLOUD !== 'true' && !base.is_meta) {
const info = await populateMeta(source, base);

2
packages/nocodb/src/services/utils.service.ts

@ -310,7 +310,7 @@ export class UtilsService {
// sorts count
Noco.ncMeta.metaCount(base.id, null, MetaTable.SORT),
// row count per base
base.getBases().then(async (sources) => {
base.getSources().then(async (sources) => {
return this.extractResultOrNull(
await Promise.allSettled(
sources.map(async (source) =>

4
packages/nocodb/tests/unit/factory/column.ts

@ -194,7 +194,7 @@ const createRollupColumn = async (
relatedTableColumnTitle: string;
},
) => {
const childBases = await base.getBases();
const childBases = await base.getSources();
const childTable = await Model.getByIdOrName({
base_id: base.id,
source_id: childBases[0].id!,
@ -243,7 +243,7 @@ const createLookupColumn = async (
relationColumnId?: string;
},
) => {
const childBases = await base.getBases();
const childBases = await base.getSources();
const childTable = await Model.getByIdOrName({
base_id: base.id,
source_id: childBases[0].id!,

2
packages/nocodb/tests/unit/factory/row.ts

@ -224,7 +224,7 @@ const listRow = async ({
sortArr?: Sort[];
};
}) => {
const sources = await base.getBases();
const sources = await base.getSources();
const baseModel = await Model.getBaseModelSQL({
id: table.id,
dbDriver: await NcConnectionMgrv2.get(sources[0]!),

4
packages/nocodb/tests/unit/factory/table.ts

@ -27,7 +27,7 @@ const getTable = async ({
base: Base;
name: string;
}) => {
const sources = await base.getBases();
const sources = await base.getSources();
return await Model.getByIdOrName({
base_id: base.id,
source_id: sources[0].id!,
@ -36,7 +36,7 @@ const getTable = async ({
};
const getAllTables = async ({ base }: { base: Base }) => {
const sources = await base.getBases();
const sources = await base.getSources();
const tables = await Model.list({
base_id: base.id,
source_id: sources[0].id!,

2
packages/nocodb/tests/unit/init/cleanupMeta.ts

@ -11,7 +11,7 @@ const dropTablesAllNonExternalProjects = async () => {
bases
.filter((base) => base.is_meta)
.map(async (base) => {
await base.getBases();
await base.getSources();
const source = base.sources && base.sources[0];
if (!source) return;

Loading…
Cancel
Save