Skip to content

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

Draft
EmilJunker wants to merge 10 commits intomasterfrom
schema-investigationsample
Draft

Add many-to-many relationship InvestigationSample to the schema#294
EmilJunker wants to merge 10 commits intomasterfrom
schema-investigationsample

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.

@RKrahl RKrahl added this to the 7.0.0 milestone Aug 4, 2025
@RKrahl RKrahl marked this pull request as draft January 12, 2026 07:19
the relationship from Investigation to Sample.  This is currently
broken and need to be reviewed.
- set CREATE_ID and MOD_ID to the constant value 'schema_upgrade',
- also set MOD_ID and MOD_TIME when setting a PID value in SAMPLE,
- use prefix '_local' in the PID values set in SAMPLE.

Still need to review the oracle upgrade script accordingly.
- set CREATE_ID and MOD_ID to the constant value 'schema_upgrade',
- also set MOD_ID and MOD_TIME when setting a PID value in SAMPLE,
- use prefix '_local' in the PID values set in SAMPLE.
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