Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ZainVirani
Copy link
Contributor

Ensures the front end only shows one link to each page of an instrument via the UNIQUE constraint in instrument_subtests.

… to ensure frontend only shows one link to each page of an instrument
@ZainVirani ZainVirani added the Category: Bug PR or issue that aims to report or fix a bug label May 11, 2017
@ZainVirani ZainVirani added this to the 17.1 milestone May 11, 2017
`Subtest_name` varchar(255) NOT NULL default '',
`Description` varchar(255) NOT NULL default '',
`Order_number` int(11) NOT NULL default '0',
UNIQUE (Subtest_name),
Copy link
Contributor

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;
Copy link
Collaborator

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 ?

Copy link
Contributor

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.

@ridz1208
Copy link
Collaborator

@ZainVirani What happens if duplicates do exist in the table ?

@ZainVirani
Copy link
Contributor Author

@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.

@ridz1208
Copy link
Collaborator

@ZainVirani and if you run this patch what will happen to the non-unique values ? is it gonna throw an error ??

@ZainVirani
Copy link
Contributor Author

ZainVirani commented May 11, 2017

@ridz1208 the patch fails
ERROR 1062 (23000): Duplicate entry 'VALUE' for key 'Subtest_name'

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.

@ZainVirani
Copy link
Contributor Author

@ridz1208 edited the sql patch to delete duplicate entries before adding the UNIQUE constraint for key Subtest_name

Copy link
Collaborator

@driusan driusan left a 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.

`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`),
Copy link
Collaborator

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)

@driusan driusan dismissed their stale review May 23, 2017 19:16

my changes were addressed

@driusan
Copy link
Collaborator

driusan commented May 31, 2017

@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
Copy link
Contributor

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.

@ZainVirani
Copy link
Contributor Author

@xlecours changes have been made

@sruthymathew123
Copy link
Contributor

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.
So I am putting passed manual tests from my part.

@sruthymathew123 sruthymathew123 added the Passed manual tests PR has been successfully tested by at least one peer label Jun 8, 2017
@ridz1208
Copy link
Collaborator

ridz1208 commented Jun 8, 2017

@davidblader please test as well on our DB

@davidblader
Copy link
Contributor

LGTM

@driusan driusan merged commit a266b9b into aces:17.1-dev Jun 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Category: Bug PR or issue that aims to report or fix a bug Passed manual tests PR has been successfully tested by at least one peer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants