Add many-to-many relationship InvestigationSample to the schema #294
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This replaces the old pull request #240 and closes #231. It turns the one-to-many relationship between
Investigation
andSample
into a many-to-many relationship. Consequently, it also changes the uniqueness constraint of theSample
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:
InvestigationSample
to the schema(representing a many-to-many relationship between
Investigation
andSample
).Sample
table frominvestigation, name
to justpid
(adding a NOT NULL constraint for
pid
while also keeping the existing NOT NULL constraint forname
).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 currentlyNULL
, the upgrade script sets thepid
to 'local:<id>' (reusing the internalid
attribute). However, in the current ICAT schema, thepid
field has no unique constraint. This means that there could theoretically be two samples with the samepid
. Or perhaps there could be several samples with thepid
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
andSample
to the newInvestigationSample
table. Once this is done, the unique constraints on theSample
table are updated and theSample.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.