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

Bunch of SQLAlchemy definitions #1192

Merged
merged 3 commits into from
Oct 4, 2024

Conversation

maximemulder
Copy link
Contributor

This is bunch of SQLAlchemy definitions I extracted from my various PRs in order to make them easier to review.

These definitions do not interact with the current code without the related PRs. Nevertheless, the (few) unit tests work, and the manual tests I did on each PR worked as well. I don't think there is any testing to do on this PR as it will be done when we review the related PRs instead, as well as with the integration testing when possible.

@maximemulder maximemulder added the A-ORM Area: ORM. Issues and pull requests related to the SQLAlchemy integration label Oct 1, 2024
@maximemulder maximemulder changed the title bunch of mysql definitions Bunch of SQLAlchemy definitions Oct 1, 2024
@maximemulder maximemulder force-pushed the 2024-10-09_bunch-mysqlalchemy-defs branch 4 times, most recently from c3add28 to 5d550fa Compare October 1, 2024 20:25
mri_qc_first_change_time : Mapped[Optional[datetime]] = mapped_column('MRIQCFirstChange')
mri_qc_last_change_time : Mapped[Optional[datetime]] = mapped_column('MRIQCLastChange')
mri_caveat : Mapped[str] = mapped_column('MRICaveat')
language_id : Mapped[Optional[int]] = mapped_column('languageID')

candidate : Mapped['db_candidate.DbCandidate'] = relationship('DbCandidate', back_populates='sessions')
Copy link
Collaborator

@cmadjar cmadjar Oct 4, 2024

Choose a reason for hiding this comment

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

I think it is missing the CohortID foreign key and relationship here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is also missing the ProjectID table definition and the relationship with session and candidate

@@ -15,10 +19,10 @@ class DbCandidate(Base):
dete_of_death : Mapped[Optional[date]] = mapped_column('DoD')
edc : Mapped[Optional[date]] = mapped_column('EDC')
sex : Mapped[Optional[str]] = mapped_column('Sex')
registration_site_id : Mapped[int] = mapped_column('RegistrationCenterID')
registration_site_id : Mapped[int] = mapped_column('RegistrationCenterID', ForeignKey('psc.CenterID'))
Copy link
Collaborator

Choose a reason for hiding this comment

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

missing FK for ProjectID and Project table definition

return db.execute(select(DbConfig)
.join(DbConfig.setting)
.where(DbConfigSetting.name == name)
).scalar_one()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is possible that a config is not set in which case this would return None.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess that if the config is not existent it will raise an exception but do we catch those? What is the error message when that happens?

Copy link
Contributor Author

@maximemulder maximemulder Oct 4, 2024

Choose a reason for hiding this comment

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

For now it raises an exception, but in the future I was planning to have a python/lib/config.py module to make the queries and handle the exceptions by exiting the program (unless the setting can be None, in which case it should probably return None).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think some Config could be not set (like the S3 configs) so probably best to support those cases.

def get_notification_type_with_name(db: Database, name: str):
"""
Get a notification type from the database using its configuration setting name, or raise an
exception if no notification type is found.
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we want to raise an exception if notification type is not existant or do we want to create the notification type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current code does not create the notification type, but I thought about it and I agree creating it would probably be the better option.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, that is what I assumed. I think for now it is fine but we could probably add that in the future. The same way we create the parameter_type when it does not exist. I don't think this is high priority though.


def try_get_site_with_psc_id_visit_label(db: Database, psc_id: str, visit_label: str):
"""
Get a session from the database using its candidate CandID and visit label, or return `None`
Copy link
Collaborator

Choose a reason for hiding this comment

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

the doc says it uses the candID but the query uses the PSCID.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, that is indeed an oversight on my part, I'll be fixing that !

@maximemulder
Copy link
Contributor Author

@cmadjar With regards to the missing foreign keys, I did not add foreign keys to table that do not have an ORM definition yet, and was planning to do it later. But I can add the other ORM tables in this PR if you want to.

@cmadjar
Copy link
Collaborator

cmadjar commented Oct 4, 2024

@maximemulder I thought about the Project table because it can be useful when handling sessions potentially. I realize that the other imaging tables are not there yet but it can be done in a separate PR.

@cmadjar cmadjar added this to the 27.0 milestone Oct 4, 2024
@maximemulder maximemulder added the S-Medium Size: Medium. Moderately-sized pull requests that are not too complex but not trivial either label Oct 4, 2024
@maximemulder maximemulder force-pushed the 2024-10-09_bunch-mysqlalchemy-defs branch from 5d550fa to cc63fe6 Compare October 4, 2024 16:44
@maximemulder maximemulder force-pushed the 2024-10-09_bunch-mysqlalchemy-defs branch from 343c54d to d604b24 Compare October 4, 2024 16:57
Copy link
Collaborator

@cmadjar cmadjar left a comment

Choose a reason for hiding this comment

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

👍

@cmadjar cmadjar merged commit f1f3988 into aces:main Oct 4, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ORM Area: ORM. Issues and pull requests related to the SQLAlchemy integration S-Medium Size: Medium. Moderately-sized pull requests that are not too complex but not trivial either
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants