-
Notifications
You must be signed in to change notification settings - Fork 172
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
[database] Clean up mri_scan_type #9304
base: main
Are you sure you want to change the base?
[database] Clean up mri_scan_type #9304
Conversation
I would like to have some opinions on the alternatives before merging. Also I don't know who should review it so I'll just ping @ridz1208 and feel free to give your opinion or re-assign it. |
After the MRI meeting today, we agreed on the following TODOs before reviewing/merging this PR :
|
Okay, I tested in LORIS as well as LORIS-MRI (imaging pipeline: dcm2mnc -> defacing -> mnc2bids) and everythings seem to wok, PR is ready for review/mege @cmadjar @nicolasbrossard. The PR is basically a SQL patch and renaming the fields in SQL queries (and some auto-formatting, feel free to ignore whitespace changes). |
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.
@maximemulder my initial review on the LORIS side for this.
One generic comment based on the spacing I see in your PR. In LORIS, we use the following convention: 1 tab = 4 spaces. I think you need to change your editor configuration to reflect that convention.
I also added some comments for @driusan and @nicolasbrossard to benefit from their wisdom on some of the changes :)
SQL/0000-00-00-schema.sql
Outdated
@@ -675,27 +676,30 @@ CREATE TABLE `mri_protocol` ( | |||
KEY `FK_mri_protocol_1` (`ScannerID`), | |||
CONSTRAINT `FK_mri_protocol_1` FOREIGN KEY (`ScannerID`) REFERENCES `mri_scanner` (`ID`), | |||
CONSTRAINT `FK_mri_protocol_2` FOREIGN KEY (`CenterID`) REFERENCES `psc` (`CenterID`), | |||
CONSTRAINT `FK_mri_protocol_scan_type` FOREIGN KEY (`MriScanTypeID`) REFERENCES `mri_scan_type` (`ID`), |
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.
seriously, we never had a foreign key for this? Interesting...
@@ -968,7 +972,7 @@ CREATE TABLE `mri_violations_log` ( | |||
`CandID` int(6) DEFAULT NULL, | |||
`Visit_label` varchar(255) DEFAULT NULL, | |||
`CheckID` int(11) DEFAULT NULL, | |||
`Scan_type` int(11) unsigned DEFAULT NULL, | |||
`MriScanTypeID` int(11) unsigned DEFAULT NULL, |
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.
@nicolasbrossard @driusan I am curious what you think of the DEFAULT NULL
for MriScanTypeID
of table mri_violations_log
. My understanding is that it can never be NULL
based on the code since the violations log happen after scan identification. But before we remove the DEFAULT NULL
from this table, I'd like your input. :)
Thank you!
SQL/0000-00-00-schema.sql
Outdated
CONSTRAINT `FK_mri_violations_log_scan_type` | ||
FOREIGN KEY (`MriScanTypeID`) REFERENCES `mri_scan_type` (`ID`), |
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.
fascinating, another foreign key I was sure was already there. 🤣 Aaah, the things you take for granted...
SQL/0000-00-00-schema.sql
Outdated
`MriProtocolGroupTargetID` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, | ||
`MriProtocolGroupID` INT(4) UNSIGNED NOT NULL, | ||
`ProjectID` INT(10) UNSIGNED DEFAULT NULL, | ||
`CohortID` INT(10) UNSIGNED DEFAULT NULL, | ||
`Visit_label` VARCHAR(255) DEFAULT NULL, | ||
PRIMARY KEY (`MriProtocolGroupTargetID`), | ||
CONSTRAINT `FK_mri_protocol_group_target_1` FOREIGN KEY (`MriProtocolGroupID`) REFERENCES `mri_protocol_group` (`MriProtocolGroupID`), | ||
CONSTRAINT `FK_mri_protocol_group_target_2` FOREIGN KEY (`ProjectID`) REFERENCES `Project` (`ProjectID`), | ||
CONSTRAINT `FK_mri_protocol_group_target_3` FOREIGN KEY (`CohortID`) REFERENCES `cohort` (`CohortID`), |
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.
That change should not show.
FYI - for LORIS code, one tab = 4 spaces
so you might want to update your editor to use the same convention.
SQL/0000-00-00-schema.sql
Outdated
CONSTRAINT `UK_mri_protocol_group_target` | ||
UNIQUE (`ProjectID`, `CohortID`, `Visit_label`) |
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.
@nicolasbrossard is that new unique constraint assumption correct for that table? I don't remember if we said it would be something we would change.
@maximemulder the change with that new constraint is technically not related to the scan type renaming so I would tend to send this in a separate PR to keep things separate.
ALTER TABLE `mri_protocol_group_target` | ||
ADD CONSTRAINT `UK_mri_protocol_group_target` | ||
UNIQUE (`ProjectID`, `CohortID`, `Visit_label`); |
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.
Same comment as in the default schema, just tagging this to not forget it at this place:
@nicolasbrossard is that new unique constraint assumption correct for that table? I don't remember if we said it would be something we would change.
@maximemulder the change with that new constraint is technically not related to the scan type renaming so I would tend to send this in a separate PR.
@@ -1486,7 +1486,7 @@ UNLOCK TABLES; | |||
SET SQL_MODE=@OLD_SQL_MODE; | |||
|
|||
DELETE FROM `mri_scan_type`; | |||
INSERT INTO `mri_scan_type` (ID,Scan_type) VALUES | |||
INSERT INTO `mri_scan_type` (ID,MriScanTypeID) VALUES |
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.
INSERT INTO `mri_scan_type` (ID,MriScanTypeID) VALUES | |
INSERT INTO `mri_scan_type` (ID,Name) VALUES |
I think the second field field should be Name
, not MriScanTypeID
SQL/0000-00-00-schema.sql
Outdated
@@ -530,8 +530,9 @@ SET SQL_MODE=@OLD_SQL_MODE; | |||
|
|||
CREATE TABLE `mri_scan_type` ( | |||
`ID` int(11) unsigned NOT NULL auto_increment, | |||
`Scan_type` text NOT NULL, | |||
PRIMARY KEY (`ID`) | |||
`Name` VARCHAR(255) NOT NULL, |
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.
`Name` VARCHAR(255) NOT NULL, | |
`MriScanTypeName` VARCHAR(255) NOT NULL, |
I would tend to name the fields in that table as MriScanTypeID
and MriScanTypeName
. The first one is so that we can use USING
in the queries. The second one is because when looking at the code change, if you need to look for something in the code with the Name
field, it is really not specific. However, if we use MriScanTypeName
, then you could grep that easily in the code.
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 personally do not like the TableField
naming convention as I find it verbose and repetitive (I often use SELECT t.field FROM table AS t
in my queries).
The USING
and grep arguments do make sense. However, I feel like those are answers to self-inflicted problems that are due to :
- How widespread queries are in our codebase (they should ideally be constrained to some database files).
- How raw SQL is a lot less searchable than (good) ORMs.
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.
burn 🙃
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.
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.
Hhhhm, our current SQL guidelines do not say anything about prefixing fields (outside of the ID) with the table name, so I assume not doing it would be the standard convention. Anyway, I think this is an issue that is broader than this PR, and that it should be discussed at a LORIS meeting. I am fine with blocking until a decision is taken.
I do want to say that I understand both point of views though, so although I have a preference I am not entirely dismissing your version.
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 hate to disagree with both of you (joking, I love it) but I only like the ID to have the full table name (because its used in linking and as a reference) I find the full table name redundant in other fields, if we are looking for a query we would look for the table itself in the join clause
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 tend to name the fields in that table as MriScanTypeID and MriScanTypeName. The first one is so that we can use USING in the queries. The second one is because when looking at the code change, if you need to look for something in the code with the Name field, it is really not specific. However, if we use MriScanTypeName, then you could grep that easily in the code.
After some reflexion I am ok with applying these suggestions. I'll do it if / when I have some time to work again on this PR.
1. Drop the `DEFAULT 0` for foreign key fields 2. Change `DEFAULT '0'` (or `'1'`) to `DEFAULT 0` (or `1`) for other fields, which is more correct. Omitted the `mri_protocol.Scan_type` field as it is fixed in #9304 instead.
b0e1c2b
to
e1545af
Compare
e1545af
to
e5ffba7
Compare
9dd02fa
to
e5ffba7
Compare
e5ffba7
to
90c10ef
Compare
1. Drop the `DEFAULT 0` for foreign key fields 2. Change `DEFAULT '0'` (or `'1'`) to `DEFAULT 0` (or `1`) for other fields, which is more correct. Omitted the `mri_protocol.Scan_type` field as it is fixed in aces#9304 instead.
90c10ef
to
4dff326
Compare
4dff326
to
52bea5f
Compare
Summary of changes
Scan_type
foreign key fields toMriScanTypeID
.0
formri_protocol.MriScanTypeID
(as this is a non-nullable foreign key, I don't think this should ever happen).Testing instructions
As we unfortunately have a very loose typing in LORIS, I may have missed a few bugs when adapting the scripts, but we're early on the next version development cycle so I guess it's the right time to do such changes.
Alternatives
ScanTypeID
(it's obvious it's an "MRI" scan type).files.AcquisitionTypeID
also be renamed tofiles.MriScanTypeID
?mri_scan_type.Scan_type
be renamed tomri_scan_type.Name
?Related issues
mri_protocol
tables #9284