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

Add many-to-many relationship InvestigationSample to the schema #294

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

EmilJunker
Copy link
Contributor

@EmilJunker EmilJunker commented Jul 18, 2022

This replaces the old pull request #240 and closes #231. It turns the one-to-many relationship between Investigation and Sample into a many-to-many relationship. Consequently, it also changes the uniqueness constraint of the Sample table.

I rebased the changes from #240 with the current master branch and resolved all occurring conflicts. I then pushed the branch to the official icat.server repository instead of my forked version to make it easier for others to review and to make changes. That is also the reason why I opened this new pull request (GitHub doesn't allow to change the source branch of an existing pull request).

Here is a summary of the changes:

  • Adds a new class InvestigationSample to the schema
    (representing a many-to-many relationship between Investigation and Sample).
  • Changes the unique constraint for the Sample table from investigation, name to just pid
    (adding a NOT NULL constraint for pid while also keeping the existing NOT NULL constraint for name).

Note that all the things I mentioned in #240 still apply to this pull request. Most notably, it is very much a work in progress.

Some notes about the upgrade script:

  • For all samples where the pid field is currently NULL, the upgrade script sets the pid to 'local:<id>' (reusing the internal id attribute). However, in the current ICAT schema, the pid field has no unique constraint. This means that there could theoretically be two samples with the same pid. Or perhaps there could be several samples with the pid set to '' (an empty string). The upgrade script currently does not handle these cases.

  • The upgrade script also transfers the existing one-to-many relationship between Investigation and Sample to the new InvestigationSample table. Once this is done, the unique constraints on the Sample table are updated and the Sample.investigation_id column is dropped. I'm not sure if the current implementation of the upgrade script handles all of this correctly. In other words: thorough testing is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement schema this involves changes to the ICAT schema
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make the relationship between Sample and Investigation many-to-many
2 participants