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.
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 betweenInvestigation
andSample
).Sample
table frominvestigation, name
to justpid
(adding a NOT NULL constraint forpid
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.