Updating how the 'merging' is handled, don't include the in-memory representation if it exists on disk in Couch, prefer that.
This commit is contained in:
parent
79c292538c
commit
745a05fe8d
|
@ -14,7 +14,7 @@ import {
|
||||||
CONSTANT_INTERNAL_ROW_COLS,
|
CONSTANT_INTERNAL_ROW_COLS,
|
||||||
generateJunctionTableID,
|
generateJunctionTableID,
|
||||||
} from "../../../../db/utils"
|
} from "../../../../db/utils"
|
||||||
import { isEqual, merge } from "lodash"
|
import { isEqual } 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> = {
|
||||||
|
@ -127,21 +127,17 @@ 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
|
for (const defaultTable of DEFAULT_TABLES) {
|
||||||
const definition = sql.designDoc.base("tableId")
|
// the default table doesn't exist in Couch, use the in-memory representation
|
||||||
for (let table of tables.concat(defaultTables)) {
|
if (!tables.find(table => table._id === defaultTable._id)) {
|
||||||
const tableId = table._id!
|
tables.push(defaultTable)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
const definition = sql.designDoc.base("tableId")
|
||||||
|
for (let table of tables) {
|
||||||
definition.sql.tables = {
|
definition.sql.tables = {
|
||||||
...definition.sql.tables,
|
...definition.sql.tables,
|
||||||
...mapped,
|
...mapTable(table),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return definition
|
return definition
|
||||||
|
|
Loading…
Reference in New Issue