From c8201140541001e8c411c9bb3c562b19b490f633 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 9 Apr 2024 10:43:26 +0100 Subject: [PATCH] Moving SQS table functionality into SDK, accessible to migrations. --- packages/server/src/api/controllers/table/utils.ts | 7 +++++-- packages/server/src/sdk/app/tables/index.ts | 2 ++ .../table/sqlite.ts => sdk/app/tables/internal/sqs.ts} | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) rename packages/server/src/{api/controllers/table/sqlite.ts => sdk/app/tables/internal/sqs.ts} (93%) diff --git a/packages/server/src/api/controllers/table/utils.ts b/packages/server/src/api/controllers/table/utils.ts index 6306eb25a7..c00a8c1bc2 100644 --- a/packages/server/src/api/controllers/table/utils.ts +++ b/packages/server/src/api/controllers/table/utils.ts @@ -16,7 +16,6 @@ import viewTemplate from "../view/viewBuilder" import { cloneDeep } from "lodash/fp" import { quotas } from "@budibase/pro" import { events, context } from "@budibase/backend-core" -import { addTableToSqlite } from "./sqlite" import { AutoFieldSubType, ContextUser, @@ -34,6 +33,8 @@ import { FieldTypeSubtypes, AttachmentFieldMetadata, } from "@budibase/types" +import sdk from "../../../sdk" +import env from "../../../environment" export async function clearColumns(table: Table, columnNames: string[]) { const db = context.getAppDB() @@ -343,7 +344,9 @@ class TableSaveFunctions { importRows: this.importRows, user: this.user, }) - await addTableToSqlite(table) + if (env.SQS_SEARCH_ENABLE) { + await sdk.tables.sqs.addTableToSqlite(table) + } return table } diff --git a/packages/server/src/sdk/app/tables/index.ts b/packages/server/src/sdk/app/tables/index.ts index ed71498d44..fcf7051e7c 100644 --- a/packages/server/src/sdk/app/tables/index.ts +++ b/packages/server/src/sdk/app/tables/index.ts @@ -3,6 +3,7 @@ import * as getters from "./getters" import * as updates from "./update" import * as utils from "./utils" import { migrate } from "./migration" +import * as sqs from "./internal/sqs" export default { populateExternalTableSchemas, @@ -10,4 +11,5 @@ export default { ...getters, ...utils, migrate, + sqs, } diff --git a/packages/server/src/api/controllers/table/sqlite.ts b/packages/server/src/sdk/app/tables/internal/sqs.ts similarity index 93% rename from packages/server/src/api/controllers/table/sqlite.ts rename to packages/server/src/sdk/app/tables/internal/sqs.ts index 49bd7f25c0..1e8a60c5db 100644 --- a/packages/server/src/api/controllers/table/sqlite.ts +++ b/packages/server/src/sdk/app/tables/internal/sqs.ts @@ -1,8 +1,8 @@ import { context, SQLITE_DESIGN_DOC_ID } from "@budibase/backend-core" import { FieldType, SQLiteDefinition, SQLiteType, Table } from "@budibase/types" import { cloneDeep } from "lodash" -import sdk from "../../../sdk" -import { CONSTANT_INTERNAL_ROW_COLS } from "../../../db/utils" +import tablesSdk from "../" +import { CONSTANT_INTERNAL_ROW_COLS } from "../../../../db/utils" const BASIC_SQLITE_DOC: SQLiteDefinition = { _id: SQLITE_DESIGN_DOC_ID, @@ -53,7 +53,7 @@ function mapTable(table: Table): { [key: string]: SQLiteType } { // nothing exists, need to iterate though existing tables async function buildBaseDefinition(): Promise { - const tables = await sdk.tables.getAllInternalTables() + const tables = await tablesSdk.getAllInternalTables() const definition = cloneDeep(BASIC_SQLITE_DOC) for (let table of tables) { definition.sql.tables[table._id!] = {