Fix enum defaultValue issues (#5307)
This PR fixes several issues:
- enum naming should be: {tableName}_{fieldName}_enum and respecting the
case
- defaultValue format handled in the FE should respect the one in the BE
In my opinion we should refactor the defaultValue:
- we should respect backend format: "'myDefault'" for constant default
and "0" for float, "now" for expressions, "true" for booleans. we can
rename it to defaultValueExpression if it is more clear but we should
not maintain a parallel system
- we should deprecate option: isDefaultValue which is confusing
- we should re-work backend to have a more unified approach between
fields and avoid having if everywhere about select, multiselect, and
currency cases. one unified "computeDefaultValue" function should do the
job
What is still broken:
- currency default Value on creation. I think we should do the refactor
first
- select default value edition.
These cases do not break the schema but are ignored currently
This commit is contained in:
@ -32,9 +32,9 @@ export class WorkspaceMigrationEnumService {
|
||||
}
|
||||
|
||||
const columnDefinition = migrationColumn.alteredColumnDefinition;
|
||||
const oldEnumTypeName =
|
||||
`${tableName}_${migrationColumn.currentColumnDefinition.columnName}_enum`.toLowerCase();
|
||||
const oldEnumTypeName = `${tableName}_${migrationColumn.currentColumnDefinition.columnName}_enum`;
|
||||
const tempEnumTypeName = `${oldEnumTypeName}_temp`;
|
||||
const newEnumTypeName = `${tableName}_${columnDefinition.columnName}_enum`;
|
||||
const enumValues =
|
||||
columnDefinition.enum?.map((enumValue) => {
|
||||
if (typeof enumValue === 'string') {
|
||||
@ -76,6 +76,7 @@ export class WorkspaceMigrationEnumService {
|
||||
type: columnDefinition.columnType,
|
||||
default: columnDefinition.defaultValue,
|
||||
enum: enumValues,
|
||||
enumName: newEnumTypeName,
|
||||
isArray: columnDefinition.isArray,
|
||||
isNullable: columnDefinition.isNullable,
|
||||
}),
|
||||
|
||||
@ -307,6 +307,8 @@ export class WorkspaceMigrationRunnerService {
|
||||
return;
|
||||
}
|
||||
|
||||
const enumName = `${tableName}_${migrationColumn.columnName}_enum`;
|
||||
|
||||
await queryRunner.addColumn(
|
||||
`${schemaName}.${tableName}`,
|
||||
new TableColumn({
|
||||
@ -316,6 +318,7 @@ export class WorkspaceMigrationRunnerService {
|
||||
enum: migrationColumn.enum?.filter(
|
||||
(value): value is string => typeof value === 'string',
|
||||
),
|
||||
enumName: enumName,
|
||||
isArray: migrationColumn.isArray,
|
||||
isNullable: migrationColumn.isNullable,
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user