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

Added unique constraints for entities #1073

Merged
merged 10 commits into from
May 17, 2019
Merged

Added unique constraints for entities #1073

merged 10 commits into from
May 17, 2019

Conversation

aklochkova
Copy link
Contributor

@aklochkova aklochkova requested a review from wivern April 29, 2019 17:42
Copy link
Contributor

@pavgra pavgra left a comment

Choose a reason for hiding this comment

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

Why constraint names differ across databases? This would complicate further migrations. Pls, use consistent naming. I would go for a pretty common prefix - uq_

@aklochkova aklochkova requested a review from pavgra May 16, 2019 16:53
@chrisknoll
Copy link
Collaborator

Trying to embed the ohdsi schema (which is a dynamic/user defined value) into the constraint name is a little complicated, isn't it?

Since we own the schema, we can ensure that the unique constraints are unique to the schema, right? If so, couldn't we just resort to simple naming conventsions like UQ_Table_Col type of formats, and not build dynamic sql in the migrations script?

In addition, when we are troubleshooting problems people may have with these constrtaints, if we name them directly, we'll be able to offer assistance. If it's based on some application config, it becomes a barrier for us to tell them which constraints to check/disable.

@anthonysena
Copy link
Collaborator

Agreed @chrisknoll - I'm updating the scripts to remove that from the constraint name as well as make some updates for the SQL Server migration script as I was having challenges running things against our SQL Server 2012 environment.

@anthonysena
Copy link
Collaborator

@pavgra - some notes on my changes and from my side this is ready to merge in.

The SQL Server migration script was problematic in our environment since chaining together the stored proc calls was not working well. I revised this script to use straight UPDATE statements to increment any duplicated names based on the row_number() to make them unique and then apply the constraints.

The PostgreSQL script was also causing me challenges (I'm on v9) and so I revised that a bit to make sure the procedure call had the ohdsiSchema prefix and increased the size of the duplicate_names column to accommodate values > 100 characters.

Per @chrisknoll's feedback I removed the ohdsiSchema name from the constraint across all 3 migration scripts.

@pavgra pavgra merged commit fc12285 into master May 17, 2019
@chrisknoll
Copy link
Collaborator

Branches should be deleted after merge, please.

@anthonysena anthonysena deleted the issue-1338-sql-part branch May 18, 2019 13:17
@aklochkova
Copy link
Contributor Author

aklochkova commented May 19, 2019

@anthonysena, hi! there's a bug after your changes
for example, we have the following data in concept_set table:
image

after completing this UPDATE operation


we have the following state:
image
so, rows with duplicate names (№1 and №2) appears and unique constraint can't be added.

I managed this case in my previous procedures (rename_cs_names), it should be something like
image

@anthonysena
Copy link
Collaborator

Thanks @aklochkova - you are absolutely right. Sorry to have missed that. Let me open an issue so that we can fix this migration script.

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.

Entities names should be unique
4 participants