Adding default tables to sync.
This commit is contained in:
parent
5066da2630
commit
34d073bcb7
|
@ -41,6 +41,7 @@ import {
|
||||||
getTableIDList,
|
getTableIDList,
|
||||||
} from "./filters"
|
} from "./filters"
|
||||||
import { dataFilters } from "@budibase/shared-core"
|
import { dataFilters } from "@budibase/shared-core"
|
||||||
|
import { DEFAULT_TABLE_IDS } from "../../../../constants"
|
||||||
|
|
||||||
const builder = new sql.Sql(SqlClient.SQL_LITE)
|
const builder = new sql.Sql(SqlClient.SQL_LITE)
|
||||||
const MISSING_COLUMN_REGEX = new RegExp(`no such column: .+`)
|
const MISSING_COLUMN_REGEX = new RegExp(`no such column: .+`)
|
||||||
|
@ -211,6 +212,18 @@ async function runSqlQuery(
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resyncDefinitionsRequired(status: number, message: string) {
|
||||||
|
// pre data_ prefix on column names, need to resync
|
||||||
|
return (
|
||||||
|
(status === 400 && message?.match(USER_COLUMN_PREFIX_REGEX)) ||
|
||||||
|
// default tables aren't included in definition
|
||||||
|
(status === 400 &&
|
||||||
|
DEFAULT_TABLE_IDS.find(tableId => message?.includes(tableId))) ||
|
||||||
|
// no design document found, needs a full sync
|
||||||
|
(status === 404 && message?.includes(SQLITE_DESIGN_DOC_ID))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export async function search(
|
export async function search(
|
||||||
options: RowSearchParams,
|
options: RowSearchParams,
|
||||||
table: Table
|
table: Table
|
||||||
|
@ -338,10 +351,7 @@ export async function search(
|
||||||
return response
|
return response
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
const msg = typeof err === "string" ? err : err.message
|
const msg = typeof err === "string" ? err : err.message
|
||||||
const syncAndRepeat =
|
if (resyncDefinitionsRequired(err.status, msg)) {
|
||||||
(err.status === 400 && msg?.match(USER_COLUMN_PREFIX_REGEX)) ||
|
|
||||||
(err.status === 404 && msg?.includes(SQLITE_DESIGN_DOC_ID))
|
|
||||||
if (syncAndRepeat) {
|
|
||||||
await sdk.tables.sqs.syncDefinition()
|
await sdk.tables.sqs.syncDefinition()
|
||||||
return search(options, table)
|
return search(options, table)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import {
|
||||||
generateJunctionTableID,
|
generateJunctionTableID,
|
||||||
} from "../../../../db/utils"
|
} from "../../../../db/utils"
|
||||||
import { isEqual } from "lodash"
|
import { isEqual } from "lodash"
|
||||||
|
import { DEFAULT_TABLES } from "../../../../db/defaultData/datasource_bb_default"
|
||||||
|
|
||||||
const FieldTypeMap: Record<FieldType, SQLiteType> = {
|
const FieldTypeMap: Record<FieldType, SQLiteType> = {
|
||||||
[FieldType.BOOLEAN]: SQLiteType.NUMERIC,
|
[FieldType.BOOLEAN]: SQLiteType.NUMERIC,
|
||||||
|
@ -126,8 +127,9 @@ function mapTable(table: Table): SQLiteTables {
|
||||||
// nothing exists, need to iterate though existing tables
|
// nothing exists, need to iterate though existing tables
|
||||||
async function buildBaseDefinition(): Promise<PreSaveSQLiteDefinition> {
|
async function buildBaseDefinition(): Promise<PreSaveSQLiteDefinition> {
|
||||||
const tables = await tablesSdk.getAllInternalTables()
|
const tables = await tablesSdk.getAllInternalTables()
|
||||||
|
const defaultTables = DEFAULT_TABLES
|
||||||
const definition = sql.designDoc.base("tableId")
|
const definition = sql.designDoc.base("tableId")
|
||||||
for (let table of tables) {
|
for (let table of tables.concat(defaultTables)) {
|
||||||
definition.sql.tables = {
|
definition.sql.tables = {
|
||||||
...definition.sql.tables,
|
...definition.sql.tables,
|
||||||
...mapTable(table),
|
...mapTable(table),
|
||||||
|
|
Loading…
Reference in New Issue