1
0
Fork 0
mirror of synced 2024-09-21 03:43:21 +12:00

There is a risk with default tables that the schema may exist in the DB as well as existing in memory - in this case we should merge the schemas to make sure that all possible attributes from the in memory representation, and the on disk version (which may have been updated by the user) have been captured in the SQLite schema.

This commit is contained in:
mike12345567 2024-07-12 13:51:06 +01:00
parent 5ff9599e3a
commit 79c292538c

View file

@ -14,7 +14,7 @@ import {
CONSTANT_INTERNAL_ROW_COLS, CONSTANT_INTERNAL_ROW_COLS,
generateJunctionTableID, generateJunctionTableID,
} from "../../../../db/utils" } from "../../../../db/utils"
import { isEqual } from "lodash" import { isEqual, merge } from "lodash"
import { DEFAULT_TABLES } from "../../../../db/defaultData/datasource_bb_default" import { DEFAULT_TABLES } from "../../../../db/defaultData/datasource_bb_default"
const FieldTypeMap: Record<FieldType, SQLiteType> = { const FieldTypeMap: Record<FieldType, SQLiteType> = {
@ -130,9 +130,18 @@ async function buildBaseDefinition(): Promise<PreSaveSQLiteDefinition> {
const defaultTables = DEFAULT_TABLES const defaultTables = DEFAULT_TABLES
const definition = sql.designDoc.base("tableId") const definition = sql.designDoc.base("tableId")
for (let table of tables.concat(defaultTables)) { for (let table of tables.concat(defaultTables)) {
const tableId = table._id!
let existing = definition.sql.tables[tableId]
let mapped = mapTable(table)
// there are multiple definitions for this table (default table overlap)
// when there is overlap - we have to make sure we have columns from all definitions
// this problem really only applies to sample data tables where they've been expanded
if (existing) {
mapped[tableId] = merge(mapped[tableId], existing)
}
definition.sql.tables = { definition.sql.tables = {
...definition.sql.tables, ...definition.sql.tables,
...mapTable(table), ...mapped,
} }
} }
return definition return definition