-
Notifications
You must be signed in to change notification settings - Fork 175
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
[candidate] Create Sex table and remove Sex enum #9025
Changes from 4 commits
2d77b8d
36118c2
a6fdfaf
45660ba
1400e27
f425084
f428603
644d190
a468632
ee8dc34
491362e
07bb514
8dc235c
6e39684
1cb5fcf
d39be27
cc70c16
68e6784
b096b34
b8bc55a
201e100
3a72ae7
547257c
1ae4da3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,15 @@ CREATE TABLE `language` ( | |
INSERT INTO language (language_code, language_label) VALUES | ||
('en-CA', 'English'); | ||
|
||
CREATE TABLE `sex` ( | ||
`SexID` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
`Sex` varchar(255) NOT NULL, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hhhhm, my previous comment was just a little thought I had during our meeting, but if I am to really review this pull request I guess I'll try to be more exhaustive. After giving it more thought, I am still not fully satisfied with the field names. I think having Regarding capitalization, the database sure is messy but I think it would be a good idea to maintain a consistent convention in at least the new tables. I am under the impression that this convention is unofficially singular snake_case for the table names and PascalCase for the field names. I am fine with that and this PR matches this convention, but I am still new and this impression of mine may be wrong, so can someone with more database experience than me confirm or deny it ? Finally, regarding the pointing of sex foreign keys on It would probably have been easier if I had mentionned all that earlier so sorry for the late reply ! In any case, I'd like someone with more database experience than me to also review this pull request. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ERROR 3780 (HY000) at line 155: Referencing column 'Sex' and referenced column 'Sex' in foreign key constraint 'FK_candidate_sex_1' are incompatible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That seems to match is the official policy documented in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Damn I looked at the documentation but somehow missed this file, thanks for pointing it to me. I forgot my glasses at home today so I guess I'm gonna use that as my excuse 😅 |
||
PRIMARY KEY (`SexID`), | ||
UNIQUE KEY `Sex` (`Sex`) | ||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Stores sex options available for candidates in LORIS'; | ||
|
||
INSERT INTO sex (Sex) VALUES ('Male'), ('Female'), ('Other'); | ||
|
||
CREATE TABLE `users` ( | ||
`ID` int(10) unsigned NOT NULL auto_increment, | ||
`UserID` varchar(255) NOT NULL default '', | ||
|
@@ -151,7 +160,7 @@ CREATE TABLE `candidate` ( | |
`DoB` date DEFAULT NULL, | ||
`DoD` date DEFAULT NULL, | ||
`EDC` date DEFAULT NULL, | ||
`Sex` enum('Male','Female','Other') DEFAULT NULL, | ||
`Sex` varchar(255) DEFAULT NULL, | ||
`RegistrationCenterID` integer unsigned NOT NULL DEFAULT '0', | ||
`RegistrationProjectID` int(10) unsigned NOT NULL, | ||
`Ethnicity` varchar(255) DEFAULT NULL, | ||
|
@@ -166,7 +175,7 @@ CREATE TABLE `candidate` ( | |
`flagged_other_status` enum('not_answered') DEFAULT NULL, | ||
`Testdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | ||
`Entity_type` enum('Human','Scanner') NOT NULL DEFAULT 'Human', | ||
`ProbandSex` enum('Male','Female','Other') DEFAULT NULL, | ||
`ProbandSex` varchar(255) DEFAULT NULL, | ||
`ProbandDoB` date DEFAULT NULL, | ||
PRIMARY KEY (`CandID`), | ||
UNIQUE KEY `ID` (`ID`), | ||
|
@@ -175,9 +184,13 @@ CREATE TABLE `candidate` ( | |
KEY `CandidateActive` (`Active`), | ||
KEY `FK_candidate_2_idx` (`flagged_reason`), | ||
KEY `PSCID` (`PSCID`), | ||
KEY `FK_candidate_sex_1` (`Sex`), | ||
KEY `FK_candidate_sex_2` (`ProbandSex`), | ||
CONSTRAINT `FK_candidate_1` FOREIGN KEY (`RegistrationCenterID`) REFERENCES `psc` (`CenterID`), | ||
CONSTRAINT `FK_candidate_2` FOREIGN KEY (`flagged_reason`) REFERENCES `caveat_options` (`ID`) ON DELETE RESTRICT ON UPDATE CASCADE, | ||
CONSTRAINT `FK_candidate_RegistrationProjectID` FOREIGN KEY (`RegistrationProjectID`) REFERENCES `Project` (`ProjectID`) ON UPDATE CASCADE | ||
CONSTRAINT `FK_candidate_RegistrationProjectID` FOREIGN KEY (`RegistrationProjectID`) REFERENCES `Project` (`ProjectID`) ON UPDATE CASCADE, | ||
CONSTRAINT `FK_candidate_sex_1` FOREIGN KEY (`Sex`) REFERENCES `sex` (`Sex`) ON DELETE RESTRICT ON UPDATE CASCADE, | ||
CONSTRAINT `FK_candidate_sex_2` FOREIGN KEY (`ProbandSex`) REFERENCES `sex` (`Sex`) ON DELETE RESTRICT ON UPDATE CASCADE | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
|
||
CREATE TABLE `session` ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
CREATE TABLE `sex` ( | ||
`SexID` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
`Sex` varchar(255) NOT NULL, | ||
PRIMARY KEY (`SexID`), | ||
UNIQUE KEY `Sex` (`Sex`) | ||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Stores sex options available for candidates in LORIS'; | ||
|
||
INSERT INTO sex (Sex) VALUES ('Male'), ('Female'), ('Other'); | ||
|
||
ALTER TABLE candidate | ||
MODIFY COLUMN sex varchar(255) DEFAULT NULL, | ||
MODIFY COLUMN ProbandSex varchar(255) DEFAULT NULL, | ||
ADD KEY `FK_candidate_sex_1` (`Sex`), | ||
ADD KEY `FK_candidate_sex_2` (`ProbandSex`), | ||
ADD CONSTRAINT `FK_candidate_sex_1` FOREIGN KEY (`Sex`) REFERENCES `sex` (`Sex`) ON DELETE RESTRICT ON UPDATE CASCADE, | ||
ADD CONSTRAINT `FK_candidate_sex_2` FOREIGN KEY (`ProbandSex`) REFERENCES `sex` (`Sex`) ON DELETE RESTRICT ON UPDATE CASCADE; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ class Methylation | |
'genotyping_platform', | ||
'Name' | ||
), | ||
'Sex' => \Utility::getSexList(), | ||
]; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,11 +28,7 @@ class Sex implements \JsonSerializable | |
/* @var string */ | ||
public $value; | ||
|
||
private const VALID_VALUES = array( | ||
'Male', | ||
'Female', | ||
'Other', | ||
); | ||
private $validValues = []; | ||
|
||
/** | ||
* Calls validate() immediately. | ||
|
@@ -43,10 +39,12 @@ class Sex implements \JsonSerializable | |
*/ | ||
public function __construct(string $value) | ||
{ | ||
if (!self::validate($value)) { | ||
$this->validValues = \Utility::getSexList(); | ||
|
||
if (!self::validate($value, $this->validValues)) { | ||
throw new \DomainException( | ||
'The value is not valid. Must be one of: ' | ||
. implode(', ', self::VALID_VALUES) | ||
. implode(', ', $this->validValues) | ||
); | ||
} | ||
$this->value = $value; | ||
|
@@ -55,13 +53,14 @@ public function __construct(string $value) | |
/** | ||
* Ensures that the value is well-formed. | ||
* | ||
* @param string $value The value to be validated | ||
* @param string $value The value to be validated | ||
* @param array $laidValues The restricted optional values of $value | ||
* | ||
* @return bool True if the value format is valid | ||
*/ | ||
public static function validate(string $value): bool | ||
public static function validate(string $value, array $validValues): bool | ||
{ | ||
return in_array($value, self::VALID_VALUES, true); | ||
return in_array($value, $validValues, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getSexList will return array( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kongtiaowang Made that change but still having trouble unfortunately! |
||
} | ||
|
||
/** | ||
|
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.
What purpose does this column have? It is not being used as a foreign key by any other tables and the other column in this table already has a not null/unique constraint and is being used as a foreign key into this table.
Removing it would solve the "what should it be named" debate in the thread below.
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.
True, this column is not useful. I don't mind removing it