Refactor
This commit is contained in:
parent
2bce7424f1
commit
706d0cb89c
|
@ -8,7 +8,7 @@ import {
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { DocumentType, SEPARATOR } from "../../db/utils"
|
import { DocumentType, SEPARATOR } from "../../db/utils"
|
||||||
import { InvalidColumns, DEFAULT_BB_DATASOURCE_ID } from "../../constants"
|
import { InvalidColumns, DEFAULT_BB_DATASOURCE_ID } from "../../constants"
|
||||||
import { helpers } from "@budibase/shared-core"
|
import { helpers, utils } from "@budibase/shared-core"
|
||||||
import env from "../../environment"
|
import env from "../../environment"
|
||||||
import { Knex } from "knex"
|
import { Knex } from "knex"
|
||||||
|
|
||||||
|
@ -342,44 +342,53 @@ function copyExistingPropsOver(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const SqlCopyTypeByFieldMapping: Record<FieldType, () => boolean> = {
|
let shouldKeepSchema = false
|
||||||
[FieldType.LINK]: () => {
|
switch (existingColumnType) {
|
||||||
const shouldKeepLink =
|
case FieldType.FORMULA:
|
||||||
|
case FieldType.AUTO:
|
||||||
|
case FieldType.INTERNAL:
|
||||||
|
shouldKeepSchema = true
|
||||||
|
break
|
||||||
|
|
||||||
|
case FieldType.LINK:
|
||||||
|
shouldKeepSchema =
|
||||||
existingColumnType === FieldType.LINK &&
|
existingColumnType === FieldType.LINK &&
|
||||||
tableIds.includes(column.tableId)
|
tableIds.includes(column.tableId)
|
||||||
return shouldKeepLink
|
break
|
||||||
},
|
|
||||||
[FieldType.FORMULA]: () => true,
|
|
||||||
[FieldType.AUTO]: () => true,
|
|
||||||
[FieldType.INTERNAL]: () => true,
|
|
||||||
[FieldType.STRING]: () => keepIfType(FieldType.STRING),
|
|
||||||
[FieldType.OPTIONS]: () => keepIfType(FieldType.STRING),
|
|
||||||
[FieldType.LONGFORM]: () => keepIfType(FieldType.STRING),
|
|
||||||
[FieldType.NUMBER]: () =>
|
|
||||||
keepIfType(FieldType.BOOLEAN, FieldType.NUMBER),
|
|
||||||
|
|
||||||
[FieldType.BOOLEAN]: () =>
|
case FieldType.STRING:
|
||||||
keepIfType(FieldType.BOOLEAN, FieldType.NUMBER),
|
case FieldType.OPTIONS:
|
||||||
[FieldType.ARRAY]: () => keepIfType(FieldType.JSON, FieldType.STRING),
|
case FieldType.LONGFORM:
|
||||||
[FieldType.DATETIME]: () =>
|
case FieldType.BARCODEQR:
|
||||||
keepIfType(FieldType.DATETIME, FieldType.STRING),
|
shouldKeepSchema = keepIfType(FieldType.STRING)
|
||||||
|
break
|
||||||
|
|
||||||
[FieldType.ATTACHMENTS]: () =>
|
case FieldType.NUMBER:
|
||||||
keepIfType(FieldType.JSON, FieldType.STRING),
|
case FieldType.BOOLEAN:
|
||||||
[FieldType.ATTACHMENT_SINGLE]: () =>
|
shouldKeepSchema = keepIfType(FieldType.BOOLEAN, FieldType.NUMBER)
|
||||||
keepIfType(FieldType.JSON, FieldType.STRING),
|
break
|
||||||
|
|
||||||
[FieldType.JSON]: () => keepIfType(FieldType.JSON, FieldType.STRING),
|
case FieldType.ARRAY:
|
||||||
[FieldType.BARCODEQR]: () => keepIfType(FieldType.STRING),
|
case FieldType.ATTACHMENTS:
|
||||||
|
case FieldType.ATTACHMENT_SINGLE:
|
||||||
|
case FieldType.JSON:
|
||||||
|
case FieldType.BB_REFERENCE:
|
||||||
|
shouldKeepSchema = keepIfType(FieldType.JSON, FieldType.STRING)
|
||||||
|
break
|
||||||
|
|
||||||
[FieldType.BIGINT]: () =>
|
case FieldType.DATETIME:
|
||||||
keepIfType(FieldType.BIGINT, FieldType.NUMBER),
|
shouldKeepSchema = keepIfType(FieldType.DATETIME, FieldType.STRING)
|
||||||
[FieldType.BB_REFERENCE]: () =>
|
break
|
||||||
keepIfType(FieldType.JSON, FieldType.STRING),
|
|
||||||
|
case FieldType.BIGINT:
|
||||||
|
shouldKeepSchema = keepIfType(FieldType.BIGINT, FieldType.NUMBER)
|
||||||
|
break
|
||||||
|
|
||||||
|
default:
|
||||||
|
utils.unreachable(existingColumnType)
|
||||||
}
|
}
|
||||||
|
|
||||||
const shouldCopyDelegate = SqlCopyTypeByFieldMapping[existingColumnType]
|
if (shouldKeepSchema) {
|
||||||
if (shouldCopyDelegate()) {
|
|
||||||
table.schema[key] = {
|
table.schema[key] = {
|
||||||
...existingTableSchema[key],
|
...existingTableSchema[key],
|
||||||
externalType:
|
externalType:
|
||||||
|
|
Loading…
Reference in New Issue