Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unique index created twice #7718

Merged
merged 3 commits into from
Oct 15, 2024
Merged

Fix unique index created twice #7718

merged 3 commits into from
Oct 15, 2024

Conversation

FelixMalfait
Copy link
Member

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

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This pull request addresses an issue with duplicate unique index creation in TypeORM by modifying the handling of unique constraints in composite columns and workspace migrations.

  • Modified CompositeColumnActionFactory to correctly set isUnique property for composite field columns based on both alteredFieldMetadata.isUnique and alteredProperty.isIncludedInUniqueConstraint
  • Commented out isUnique property in WorkspaceMigrationRunnerService when creating columns to prevent redundant index creation
  • These changes aim to resolve the problem of double index creation while maintaining existing functionality for unique constraints
  • The modifications may have implications on existing migrations and unique constraint management throughout the system
  • Future consideration: potentially moving unique constraint handling to the field level in a later step

2 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +186 to 190
isUnique:
(alteredFieldMetadata.isUnique &&
alteredProperty.isIncludedInUniqueConstraint) ??
false,
defaultValue: serializedDefaultValue,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: This change ensures that isUnique is only set when both the field is unique and the specific property is included in the unique constraint. Make sure this logic is consistent with the intended behavior for composite fields.

Copy link
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Weiko
Copy link
Member

Weiko commented Oct 15, 2024

I think you can put back the index decorator in person entity? 🙂 @FelixMalfait

@FelixMalfait FelixMalfait merged commit f3fe3ab into main Oct 15, 2024
8 checks passed
@FelixMalfait FelixMalfait deleted the fix-index-empty-string branch October 15, 2024 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants