Moving SQS table functionality into SDK, accessible to migrations.

This commit is contained in:
mike12345567 2024-04-09 10:43:26 +01:00
parent ef46afe530
commit c820114054
3 changed files with 10 additions and 5 deletions

View File

@ -16,7 +16,6 @@ import viewTemplate from "../view/viewBuilder"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import { quotas } from "@budibase/pro" import { quotas } from "@budibase/pro"
import { events, context } from "@budibase/backend-core" import { events, context } from "@budibase/backend-core"
import { addTableToSqlite } from "./sqlite"
import { import {
AutoFieldSubType, AutoFieldSubType,
ContextUser, ContextUser,
@ -34,6 +33,8 @@ import {
FieldTypeSubtypes, FieldTypeSubtypes,
AttachmentFieldMetadata, AttachmentFieldMetadata,
} from "@budibase/types" } from "@budibase/types"
import sdk from "../../../sdk"
import env from "../../../environment"
export async function clearColumns(table: Table, columnNames: string[]) { export async function clearColumns(table: Table, columnNames: string[]) {
const db = context.getAppDB() const db = context.getAppDB()
@ -343,7 +344,9 @@ class TableSaveFunctions {
importRows: this.importRows, importRows: this.importRows,
user: this.user, user: this.user,
}) })
await addTableToSqlite(table) if (env.SQS_SEARCH_ENABLE) {
await sdk.tables.sqs.addTableToSqlite(table)
}
return table return table
} }

View File

@ -3,6 +3,7 @@ import * as getters from "./getters"
import * as updates from "./update" import * as updates from "./update"
import * as utils from "./utils" import * as utils from "./utils"
import { migrate } from "./migration" import { migrate } from "./migration"
import * as sqs from "./internal/sqs"
export default { export default {
populateExternalTableSchemas, populateExternalTableSchemas,
@ -10,4 +11,5 @@ export default {
...getters, ...getters,
...utils, ...utils,
migrate, migrate,
sqs,
} }

View File

@ -1,8 +1,8 @@
import { context, SQLITE_DESIGN_DOC_ID } from "@budibase/backend-core" import { context, SQLITE_DESIGN_DOC_ID } from "@budibase/backend-core"
import { FieldType, SQLiteDefinition, SQLiteType, Table } from "@budibase/types" import { FieldType, SQLiteDefinition, SQLiteType, Table } from "@budibase/types"
import { cloneDeep } from "lodash" import { cloneDeep } from "lodash"
import sdk from "../../../sdk" import tablesSdk from "../"
import { CONSTANT_INTERNAL_ROW_COLS } from "../../../db/utils" import { CONSTANT_INTERNAL_ROW_COLS } from "../../../../db/utils"
const BASIC_SQLITE_DOC: SQLiteDefinition = { const BASIC_SQLITE_DOC: SQLiteDefinition = {
_id: SQLITE_DESIGN_DOC_ID, _id: SQLITE_DESIGN_DOC_ID,
@ -53,7 +53,7 @@ function mapTable(table: Table): { [key: string]: SQLiteType } {
// nothing exists, need to iterate though existing tables // nothing exists, need to iterate though existing tables
async function buildBaseDefinition(): Promise<SQLiteDefinition> { async function buildBaseDefinition(): Promise<SQLiteDefinition> {
const tables = await sdk.tables.getAllInternalTables() const tables = await tablesSdk.getAllInternalTables()
const definition = cloneDeep(BASIC_SQLITE_DOC) const definition = cloneDeep(BASIC_SQLITE_DOC)
for (let table of tables) { for (let table of tables) {
definition.sql.tables[table._id!] = { definition.sql.tables[table._id!] = {