Skip to content

Ensure FKs and indices in targetedms schema#1187

Open
ankurjuneja wants to merge 2 commits intorelease26.3-SNAPSHOTfrom
26.3_fb_Issue894_ensureFK
Open

Ensure FKs and indices in targetedms schema#1187
ankurjuneja wants to merge 2 commits intorelease26.3-SNAPSHOTfrom
26.3_fb_Issue894_ensureFK

Conversation

@ankurjuneja
Copy link
Contributor

@ankurjuneja ankurjuneja commented Mar 25, 2026

Rationale

Add missing foreign key to core.Containers and add missing dedicated index on containers on columns.
26.002-26.003 upgrade script is here #1185

Related Pull Requests

Changes

These tables have the Container column but lack a formal FOREIGN KEY constraint to the core.Containers table.

  • targetedms.Runs
  • targetedms.QCAnnotation
  • targetedms.GuideSet
  • targetedms.AutoQCPing
  • targetedms.PrecursorChromInfo
  • targetedms.SampleFileChromInfo

missing index:

  • targetedms.QCAnnotationType
  • targetedms.QCAnnotation
  • targetedms.GuideSet
  • targetedms.QCMetricConfiguration

@ankurjuneja
Copy link
Contributor Author

The failing test is already assigned in TC.

Copy link
Contributor

@labkey-jeckels labkey-jeckels left a comment

Choose a reason for hiding this comment

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

One or two requests.

Comment on lines +3 to +5
ALTER TABLE targetedms.QCAnnotation ADD CONSTRAINT FK_QCAnnotation_Container FOREIGN KEY (Container) REFERENCES core.Containers(EntityId);
ALTER TABLE targetedms.GuideSet ADD CONSTRAINT FK_GuideSet_Container FOREIGN KEY (Container) REFERENCES core.Containers(EntityId);
ALTER TABLE targetedms.AutoQCPing ADD CONSTRAINT FK_AutoQCPing_Container FOREIGN KEY (Container) REFERENCES core.Containers(EntityId);
Copy link
Contributor

Choose a reason for hiding this comment

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

These three could easily be deleted as part of the upgrade in case there are orphaned rows.

The other three would be harder because they have many more FKs pointed at them. Maybe we should do what I helped the MacCoss lab do - reparent any orphaned rows in Runs, PrecursorChromInfo, or SampleFileChromInfo to the /Shared project before doing the delete.

new SqlExecutor(TargetedMSManager.getSchema()).execute("DELETE FROM " + TargetedMSManager.getTableInfoMSInstrument() + " WHERE Container = ?", c);
new SqlExecutor(TargetedMSManager.getSchema()).execute("DELETE FROM " + TargetedMSManager.getTableInfoPaymentMethod() + " WHERE Container = ?", c);
new SqlExecutor(TargetedMSManager.getSchema()).execute("DELETE FROM " + TargetedMSManager.getTableInfoRateType() + " WHERE Container = ?", c);
new SqlExecutor(TargetedMSManager.getSchema()).execute("DELETE FROM " + TargetedMSManager.getTableInfoSampleFileChromInfo() + " WHERE Container = ?", c);
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is needed, it means that the call to deleteSampleFileDependent(getTableInfoSampleFileChromInfo()) in TargetedMSManager.purgeDeletedRuns() isn't doing what it should, or there's another codepath that should be doing the same thing.

Were there test failures or other repros that inspired adding it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants