Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SELECT core.executeJavaUpgradeCode('reparentOrphanedTargetedMSData');

-- Adding missing foreign keys to core.Containers(EntityId)
ALTER TABLE targetedms.Runs ADD CONSTRAINT FK_Runs_Container FOREIGN KEY (Container) REFERENCES core.Containers(EntityId);
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);
ALTER TABLE targetedms.PrecursorChromInfo ADD CONSTRAINT FK_PrecursorChromInfo_Container FOREIGN KEY (Container) REFERENCES core.Containers(EntityId);
ALTER TABLE targetedms.SampleFileChromInfo ADD CONSTRAINT FK_SampleFileChromInfo_Container FOREIGN KEY (Container) REFERENCES core.Containers(EntityId);

-- Adding missing indices on Container
CREATE INDEX IX_QCAnnotationType_Container ON targetedms.QCAnnotationType(Container);
CREATE INDEX IX_QCAnnotation_Container ON targetedms.QCAnnotation(Container);
CREATE INDEX IX_GuideSet_Container ON targetedms.GuideSet(Container);
CREATE INDEX IX_QCMetricConfiguration_Container ON targetedms.QCMetricConfiguration(Container);
11 changes: 11 additions & 0 deletions src/org/labkey/targetedms/TargetedMSManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2524,6 +2524,17 @@ public void moveRun(TargetedMSRun run, Container newContainer, String newRunLSID

new SqlExecutor(getSchema()).execute(updatePrecChromInfoSql);

SQLFragment updateSampleFileChromInfoSql = new SQLFragment("UPDATE ");
updateSampleFileChromInfoSql.append(getTableInfoSampleFileChromInfo(), "");
updateSampleFileChromInfoSql.append(" SET container = ?").add(newContainer);
updateSampleFileChromInfoSql.append(" WHERE sampleFileId IN (");
updateSampleFileChromInfoSql.append(" SELECT sf.Id FROM ").append(getTableInfoSampleFile(), "sf");
updateSampleFileChromInfoSql.append(" INNER JOIN ").append(getTableInfoReplicate(), "rep").append(" ON rep.Id = sf.ReplicateId");
updateSampleFileChromInfoSql.append(" WHERE rep.runId = ?").add(run.getId());
updateSampleFileChromInfoSql.append(" )");

new SqlExecutor(getSchema()).execute(updateSampleFileChromInfoSql);

run.setExperimentRunLSID(newRunLSID);
run.setDataId(newDataRowId);
run.setContainer(newContainer);
Expand Down
2 changes: 1 addition & 1 deletion src/org/labkey/targetedms/TargetedMSModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public String getName()
@Override
public Double getSchemaVersion()
{
return 26.003;
return 26.004;
}

@Override
Expand Down
38 changes: 38 additions & 0 deletions src/org/labkey/targetedms/TargetedMSUpgradeCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,42 @@ public void populatePTMPercentsGroupedPrepivotCache(final ModuleContext moduleCo

LOG.info("Finished populating PTMPercentsGroupedPrepivotCache for existing ExperimentMAM folders");
}

@SuppressWarnings("UnusedDeclaration")
public void reparentOrphanedTargetedMSData(final ModuleContext moduleContext)
{
if (moduleContext.isNewInstall())
{
return;
}

Container sharedContainer = ContainerManager.getSharedContainer();

SqlExecutor executor = new SqlExecutor(TargetedMSManager.getSchema());

String[] tablesToDeleteOrphans = {"QCAnnotation", "GuideSet", "AutoQCPing"};
for (String tableName : tablesToDeleteOrphans)
{
SQLFragment deleteSql = new SQLFragment("DELETE FROM targetedms.").append(tableName)
.append(" WHERE Container NOT IN (SELECT EntityId FROM core.Containers)");
int deletedCount = executor.execute(deleteSql);
if (deletedCount > 0)
{
LOG.info("Deleted " + deletedCount + " orphaned rows from targetedms." + tableName);
}
}

String[] tablesToReparentOrphans = {"Runs", "PrecursorChromInfo", "SampleFileChromInfo"};
for (String tableName : tablesToReparentOrphans)
{
SQLFragment updateSql = new SQLFragment("UPDATE targetedms.").append(tableName)
.append(" SET Container = ? WHERE Container NOT IN (SELECT EntityId FROM core.Containers)")
.add(sharedContainer.getEntityId());
int updatedCount = executor.execute(updateSql);
if (updatedCount > 0)
{
LOG.info("Reparented " + updatedCount + " orphaned rows from targetedms." + tableName + " to /Shared");
}
}
}
}
Loading