Fix unique index created twice (#7718)

`isUnique` was passed to TypeORM's column creation API resulting in
double index creation because it's already done via the decorator and
then in `WorkspaceMigrationIndexFactory`

It would be interesting to move it at this field level in a later step,
which is why I also fixed `CompositeColumnActionFactory` to pass
isUnique on the correct columns, even though it's being ignored later on
This commit is contained in:
Félix Malfait
2024-10-15 17:50:39 +02:00
committed by GitHub
parent 7e808cf529
commit f3fe3abf71
3 changed files with 9 additions and 5 deletions

View File

@ -183,7 +183,10 @@ export class CompositeColumnActionFactory extends ColumnActionAbstractFactory<Co
enum: enumOptions,
isNullable:
alteredFieldMetadata.isNullable || !alteredProperty.isRequired,
isUnique: alteredFieldMetadata.isUnique ?? false,
isUnique:
(alteredFieldMetadata.isUnique &&
alteredProperty.isIncludedInUniqueConstraint) ??
false,
defaultValue: serializedDefaultValue,
isArray:
alteredProperty.type === FieldMetadataType.MULTI_SELECT ||

View File

@ -402,7 +402,10 @@ export class WorkspaceMigrationRunnerService {
enumName: enumName,
isArray: migrationColumn.isArray,
isNullable: migrationColumn.isNullable,
isUnique: migrationColumn.isUnique,
/* For now unique constraints are created at a higher level
as we need to handle soft-delete and a bug on empty strings
*/
// isUnique: migrationColumn.isUnique,
asExpression: migrationColumn.asExpression,
generatedType: migrationColumn.generatedType,
}),