-
Notifications
You must be signed in to change notification settings - Fork 189
[Core] Added UNIQUE constraint to Subtest_name in instrument_subtests #2798
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
Conversation
… to ensure frontend only shows one link to each page of an instrument
SQL/0000-00-00-schema.sql
Outdated
| `Subtest_name` varchar(255) NOT NULL default '', | ||
| `Description` varchar(255) NOT NULL default '', | ||
| `Order_number` int(11) NOT NULL default '0', | ||
| UNIQUE (Subtest_name), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to explicitly name the unique key.
ex:
UNIQUE KEY `Subtest_name` (`Subtest_name`)
| @@ -0,0 +1,8 @@ | |||
| WARNINGS; | |||
| SET SQL_NOTES=1; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xlecours should the original value be saved to a variable first and reset after the patch ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ridz1208 No, it is a session variable.
|
@ZainVirani What happens if duplicates do exist in the table ? |
|
@ridz1208 Under Subtests on the left sidebar multiple links to the same page of an instrument can appear (Page 1, Page 1, Page 1, all of which link to page 1 of the instrument). This only occurs if an INSERT statement to instrument_subtests with the same values is run more than once. |
|
@ZainVirani and if you run this patch what will happen to the non-unique values ? is it gonna throw an error ?? |
|
@ridz1208 the patch fails Edit: if its worth doing, tomorrow I can try to either edit the .sql patch to delete duplicate entries, or a php script to do the same. |
|
@ridz1208 edited the sql patch to delete duplicate entries before adding the UNIQUE constraint for key Subtest_name |
driusan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to break some studies as it's currently written.
SQL/0000-00-00-schema.sql
Outdated
| `Subtest_name` varchar(255) NOT NULL default '', | ||
| `Description` varchar(255) NOT NULL default '', | ||
| `Order_number` int(11) NOT NULL default '0', | ||
| UNIQUE KEY `Subtest_name` (`Subtest_name`), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this constraint makes sense. Subtest_name is the name of the page, but different instruments might have pages with the same name. (ie. different instruments might both have different pages both named "page2")
The constraint should be on the combination of (Test_name, Subtest_name)
|
@xlecours can you dismiss your review or re-review? |
|
|
||
| SELECT 'Alter instrument_subtests to force unique Subtest_name' as 'Step #1'; | ||
| SELECT 'Delete duplicate entries' as 'Step #1'; | ||
| DELETE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'LORIS_17_1.instrument_subtests.ID' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
I would suggest usign this synthax:
DELETE FROM instrument_subtests USING instrument_subtests, instrument_subtests to_keep WHERE instrument_subtests.ID < to_keep.ID AND instrument_subtests.Test_name = to_keep.Test_name AND instrument_subtests.Subtest_name = to_keep.Subtest_name;
This should keep the latest record according to auto_increment.
|
@xlecours changes have been made |
|
The script ran smooth on my database. Seems it added the unique key constaint on the defined fields. After that I tried creating a duplicate entry and the duplicate entry warning was poping up. |
|
@davidblader please test as well on our DB |
|
LGTM |
Ensures the front end only shows one link to each page of an instrument via the UNIQUE constraint in instrument_subtests.