diff --git a/packages/server/src/sdk/app/tables/internal/sqs.ts b/packages/server/src/sdk/app/tables/internal/sqs.ts index fc0ee8fc0b..aeaa33ed2d 100644 --- a/packages/server/src/sdk/app/tables/internal/sqs.ts +++ b/packages/server/src/sdk/app/tables/internal/sqs.ts @@ -14,7 +14,7 @@ import { CONSTANT_INTERNAL_ROW_COLS, generateJunctionTableID, } from "../../../../db/utils" -import { isEqual } from "lodash" +import { isEqual, merge } from "lodash" import { DEFAULT_TABLES } from "../../../../db/defaultData/datasource_bb_default" const FieldTypeMap: Record = { @@ -130,9 +130,18 @@ async function buildBaseDefinition(): Promise { const defaultTables = DEFAULT_TABLES const definition = sql.designDoc.base("tableId") 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, - ...mapTable(table), + ...mapped, } } return definition