Keep schema by default

This commit is contained in:
Adria Navarro 2024-04-16 14:34:06 +02:00
parent 3e32ce4d24
commit 4aba988ca9
1 changed files with 24 additions and 17 deletions

View File

@ -284,8 +284,8 @@ export function isIsoDateString(str: string) {
* @param column The column to check, to see if it is a valid relationship. * @param column The column to check, to see if it is a valid relationship.
* @param tableIds The IDs of the tables which currently exist. * @param tableIds The IDs of the tables which currently exist.
*/ */
export function shouldCopyRelationship( function shouldCopyRelationship(
column: { type: string; tableId?: string }, column: { type: FieldType.LINK; tableId?: string },
tableIds: string[] tableIds: string[]
) { ) {
return ( return (
@ -303,28 +303,18 @@ export function shouldCopyRelationship(
* @param column The column to check for options or boolean type. * @param column The column to check for options or boolean type.
* @param fetchedColumn The fetched column to check for the type in the external database. * @param fetchedColumn The fetched column to check for the type in the external database.
*/ */
export function shouldCopySpecialColumn( function shouldCopySpecialColumn(
column: { type: string }, column: { type: string },
fetchedColumn: { type: string } | undefined fetchedColumn: { type: string } | undefined
) { ) {
const isFormula = column.type === FieldType.FORMULA const isFormula = column.type === FieldType.FORMULA
const specialTypes = [
FieldType.OPTIONS,
FieldType.LONGFORM,
FieldType.ARRAY,
FieldType.FORMULA,
FieldType.BB_REFERENCE,
]
// column has been deleted, remove - formulas will never exist, always copy // column has been deleted, remove - formulas will never exist, always copy
if (!isFormula && column && !fetchedColumn) { if (!isFormula && column && !fetchedColumn) {
return false return false
} }
const fetchedIsNumber = const fetchedIsNumber =
!fetchedColumn || fetchedColumn.type === FieldType.NUMBER !fetchedColumn || fetchedColumn.type === FieldType.NUMBER
return ( return fetchedIsNumber && column.type === FieldType.BOOLEAN
specialTypes.indexOf(column.type as FieldType) !== -1 ||
(fetchedIsNumber && column.type === FieldType.BOOLEAN)
)
} }
/** /**
@ -357,12 +347,29 @@ function copyExistingPropsOver(
continue continue
} }
const column = existingTableSchema[key] const column = existingTableSchema[key]
if ( if (
shouldCopyRelationship(column, tableIds) || column.type === FieldType.LINK &&
shouldCopySpecialColumn(column, table.schema[key]) !shouldCopyRelationship(column, tableIds)
) { ) {
table.schema[key] = existingTableSchema[key] continue
} }
const specialTypes = [
FieldType.OPTIONS,
FieldType.LONGFORM,
FieldType.ARRAY,
FieldType.FORMULA,
FieldType.BB_REFERENCE,
]
if (
specialTypes.includes(column.type) &&
!shouldCopySpecialColumn(column, table.schema[key])
) {
continue
}
table.schema[key] = existingTableSchema[key]
} }
} }
return table return table