Merge pull request #13512 from Budibase/budi-8126/fix-changing-column-type

Fix changing column type
This commit is contained in:
Adria Navarro 2024-04-17 17:27:10 +02:00 committed by GitHub
commit c986cf2b56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 8 deletions

View File

@ -56,8 +56,8 @@
let primaryDisplay
let indexes = [...($tables.selected.indexes || [])]
let isCreating = undefined
let relationshipPart1 = PrettyRelationshipDefinitions.Many
let relationshipPart2 = PrettyRelationshipDefinitions.One
let relationshipPart1 = PrettyRelationshipDefinitions.MANY
let relationshipPart2 = PrettyRelationshipDefinitions.ONE
let relationshipTableIdPrimary = null
let relationshipTableIdSecondary = null
let table = $tables.selected
@ -170,7 +170,7 @@
$: typeEnabled =
!originalName ||
(originalName &&
SWITCHABLE_TYPES[editableColumn.type] &&
SWITCHABLE_TYPES[field.type] &&
!editableColumn?.autocolumn)
const fieldDefinitions = Object.values(FIELDS).reduce(
@ -363,9 +363,14 @@
function getAllowedTypes() {
if (originalName) {
return (
SWITCHABLE_TYPES[editableColumn.type] || [editableColumn.type]
).map(f => FIELDS[f.toUpperCase()])
const possibleTypes = (
SWITCHABLE_TYPES[field.type] || [editableColumn.type]
).map(t => t.toLowerCase())
return Object.entries(FIELDS)
.filter(([fieldType]) =>
possibleTypes.includes(fieldType.toLowerCase())
)
.map(([_, fieldDefinition]) => fieldDefinition)
}
const isUsers =

View File

@ -64,7 +64,7 @@ export function createTablesStore() {
if (
oldField != null &&
oldField?.type !== field.type &&
SWITCHABLE_TYPES[oldField?.type]
!SWITCHABLE_TYPES[oldField?.type]?.includes(field.type)
) {
updatedTable.schema[key] = oldField
}

View File

@ -354,7 +354,7 @@ function copyExistingPropsOver(
// If the db column type changed to a non-compatible one, we want to re-fetch it
if (
updatedColumnType !== existingColumnType &&
!SWITCHABLE_TYPES[existingColumnType]?.includes(updatedColumnType)
!SWITCHABLE_TYPES[updatedColumnType]?.includes(existingColumnType)
) {
continue
}