Skip to content

Commit

Permalink
Fix unique index created twice (#7718)
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
FelixMalfait authored Oct 15, 2024
1 parent 7e808cf commit f3fe3ab
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field
import { WorkspaceIsDeprecated } from 'src/engine/twenty-orm/decorators/workspace-is-deprecated.decorator';
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator';
import { WorkspaceIsUnique } from 'src/engine/twenty-orm/decorators/workspace-is-unique.decorator';
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
import { PERSON_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
Expand Down Expand Up @@ -79,10 +80,7 @@ export class PersonWorkspaceEntity extends BaseWorkspaceEntity {
description: 'Contact’s Emails',
icon: 'IconMail',
})
/*
TODO: add back once we handle TEXT Unique index properly
@WorkspaceIsUnique()
*/
[EMAILS_FIELD_NAME]: EmailsMetadata;

@WorkspaceField({
Expand Down

0 comments on commit f3fe3ab

Please sign in to comment.