Skip to content

Commit 42202c0

Browse files
committed
Change to a dual unique constraint on ID and tag for data collection groups
1 parent 55ca500 commit 42202c0

File tree

6 files changed

+28
-1
lines changed

6 files changed

+28
-1
lines changed

src/murfey/cli/inject_spa_processing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def run():
132132
.where(DataCollectionGroup.session_id == args.session_id)
133133
.where(DataCollectionGroup.tag == args.tag)
134134
.where(DataCollection.dcg_id == DataCollectionGroup.id)
135+
.where(DataCollection.dcg_tag == DataCollectionGroup.tag)
135136
.where(ProcessingJob.dc_id == DataCollection.id)
136137
.where(AutoProcProgram.pj_id == ProcessingJob.id)
137138
.where(ProcessingJob.recipe == "em-spa-preprocess")

src/murfey/cli/spa_ispyb_messages.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ def run():
336336
.where(db.DataCollectionGroup.session_id == args.session_id)
337337
.where(db.DataCollectionGroup.tag == args.tag)
338338
.where(db.DataCollection.dcg_id == db.DataCollectionGroup.id)
339+
.where(db.DataCollection.dcg_tag == db.DataCollectionGroup.tag)
339340
.where(db.ProcessingJob.dc_id == db.DataCollection.id)
340341
.where(db.AutoProcProgram.pj_id == db.ProcessingJob.id)
341342
.where(db.ProcessingJob.recipe == "em-spa-preprocess")

src/murfey/server/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ def get_job_ids(tilt_series_id: int, appid: int) -> JobIDs:
181181
.where(db.AutoProcProgram.id == appid)
182182
.where(db.ProcessingJob.dc_id == db.DataCollection.id)
183183
.where(db.DataCollectionGroup.id == db.DataCollection.dcg_id)
184+
.where(db.DataCollectionGroup.tag == db.DataCollection.dcg_tag)
184185
.where(db.Session.id == db.TiltSeries.session_id)
185186
).all()
186187
return JobIDs(
@@ -2399,6 +2400,7 @@ def feedback_callback(header: dict, message: dict) -> None:
23992400
db.AutoProcProgram,
24002401
)
24012402
.where(db.DataCollection.dcg_id == db.DataCollectionGroup.id)
2403+
.where(db.DataCollection.dcg_tag == db.DataCollectionGroup.tag)
24022404
.where(db.ProcessingJob.dc_id == db.DataCollection.id)
24032405
.where(db.AutoProcProgram.pj_id == db.ProcessingJob.id)
24042406
.where(db.AutoProcProgram.id == message["program_id"])
@@ -2598,6 +2600,7 @@ def feedback_callback(header: dict, message: dict) -> None:
25982600
).all()
25992601
if dcg:
26002602
dcgid = dcg[0].id
2603+
dcg_tag = dcg[0].tag
26012604
# flush_data_collections(message["source"], murfey_db)
26022605
else:
26032606
logger.warning(
@@ -2610,13 +2613,15 @@ def feedback_callback(header: dict, message: dict) -> None:
26102613
select(db.DataCollection)
26112614
.where(db.DataCollection.tag == message.get("tag"))
26122615
.where(db.DataCollection.dcg_id == dcgid)
2616+
.where(db.DataCollection.dcg_tag == dcg_tag)
26132617
).all():
26142618
dcid = dc_murfey[0].id
26152619
else:
26162620
if ispyb_session_id is None:
26172621
murfey_dc = db.DataCollection(
26182622
tag=message.get("tag"),
26192623
dcg_id=dcgid,
2624+
dcg_tag=dcg_tag,
26202625
)
26212626
else:
26222627
record = DataCollection(
@@ -2649,6 +2654,7 @@ def feedback_callback(header: dict, message: dict) -> None:
26492654
id=dcid,
26502655
tag=message.get("tag"),
26512656
dcg_id=dcgid,
2657+
dcg_tag=dcg_tag,
26522658
)
26532659
murfey_db.add(murfey_dc)
26542660
murfey_db.commit()
@@ -2666,6 +2672,7 @@ def feedback_callback(header: dict, message: dict) -> None:
26662672
dc = murfey_db.exec(
26672673
select(db.DataCollection, db.DataCollectionGroup)
26682674
.where(db.DataCollection.dcg_id == db.DataCollectionGroup.id)
2675+
.where(db.DataCollection.dcg_tag == db.DataCollectionGroup.tag)
26692676
.where(db.DataCollectionGroup.session_id == murfey_session_id)
26702677
.where(db.DataCollectionGroup.tag == message["source"])
26712678
.where(db.DataCollection.tag == message["tag"])

src/murfey/server/api/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ def register_tomo_proc_params(
556556
.where(DataCollectionGroup.tag == proc_params.tag)
557557
.where(DataCollection.tag == proc_params.tilt_series_tag)
558558
.where(DataCollection.dcg_id == DataCollectionGroup.id)
559+
.where(DataCollection.dcg_tag == DataCollectionGroup.tag)
559560
.where(ProcessingJob.dc_id == DataCollection.id)
560561
.where(AutoProcProgram.pj_id == ProcessingJob.id)
561562
.where(ProcessingJob.recipe == "em-tomo-preprocess")
@@ -685,6 +686,7 @@ def register_completed_tilt_series(
685686
.where(DataCollectionGroup.tag == tilt_series_group.source)
686687
.where(DataCollection.tag == ts.tag)
687688
.where(DataCollection.dcg_id == DataCollectionGroup.id)
689+
.where(DataCollection.dcg_tag == DataCollectionGroup.tag)
688690
.where(ProcessingJob.dc_id == DataCollection.id)
689691
.where(AutoProcProgram.pj_id == ProcessingJob.id)
690692
.where(ProcessingJob.recipe == "em-tomo-align")
@@ -987,6 +989,7 @@ async def request_spa_preprocessing(
987989
.where(DataCollectionGroup.session_id == session_id)
988990
.where(DataCollectionGroup.tag == proc_file.tag)
989991
.where(DataCollection.dcg_id == DataCollectionGroup.id)
992+
.where(DataCollection.dcg_tag == DataCollectionGroup.tag)
990993
.where(ProcessingJob.dc_id == DataCollection.id)
991994
.where(AutoProcProgram.pj_id == ProcessingJob.id)
992995
.where(ProcessingJob.recipe == "em-spa-preprocess")
@@ -1136,6 +1139,7 @@ async def request_tomography_preprocessing(
11361139
.where(DataCollectionGroup.tag == proc_file.group_tag)
11371140
.where(DataCollection.tag == proc_file.tag)
11381141
.where(DataCollection.dcg_id == DataCollectionGroup.id)
1142+
.where(DataCollection.dcg_tag == DataCollectionGroup.tag)
11391143
.where(ProcessingJob.dc_id == DataCollection.id)
11401144
.where(AutoProcProgram.pj_id == ProcessingJob.id)
11411145
.where(ProcessingJob.recipe == recipe_name)
@@ -1738,6 +1742,7 @@ def register_processing_success_in_ispyb(
17381742
select(DataCollectionGroup, DataCollection, ProcessingJob, AutoProcProgram)
17391743
.where(DataCollectionGroup.session_id == session_id)
17401744
.where(DataCollection.dcg_id == DataCollectionGroup.id)
1745+
.where(DataCollection.dcg_tag == DataCollectionGroup.tag)
17411746
.where(ProcessingJob.dc_id == DataCollection.id)
17421747
.where(AutoProcProgram.pj_id == ProcessingJob.id)
17431748
).all()
@@ -1777,6 +1782,7 @@ def remove_session(client_id: int, db=murfey_db):
17771782
select(DataCollectionGroup, DataCollection, ProcessingJob)
17781783
.where(DataCollectionGroup.session_id == session_id)
17791784
.where(DataCollection.dcg_id == DataCollectionGroup.id)
1785+
.where(DataCollection.dcg_tag == DataCollectionGroup.tag)
17801786
.where(ProcessingJob.dc_id == DataCollection.id)
17811787
).all()
17821788
for c in collected_ids:

src/murfey/server/demo_api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ def get_spa_proc_param_details(
386386
)
387387
.where(DataCollectionGroup.session_id == session_id)
388388
.where(DataCollectionGroup.id == DataCollection.dcg_id)
389+
.where(DataCollectionGroup.tag == DataCollection.dcg_tag)
389390
.where(DataCollection.id == ProcessingJob.dc_id)
390391
.where(SPARelionParameters.pj_id == ProcessingJob.id)
391392
.where(SPAFeedbackParameters.pj_id == ProcessingJob.id)
@@ -437,6 +438,7 @@ def register_spa_proc_params(
437438
.where(DataCollectionGroup.session_id == session_id)
438439
.where(DataCollectionGroup.tag == proc_params.tag)
439440
.where(DataCollection.dcg_id == DataCollectionGroup.id)
441+
.where(DataCollection.dcg_tag == DataCollectionGroup.tag)
440442
.where(ProcessingJob.dc_id == DataCollection.id)
441443
.where(AutoProcProgram.pj_id == ProcessingJob.id)
442444
.where(ProcessingJob.recipe == "em-spa-preprocess")
@@ -497,6 +499,7 @@ def register_tomo_preproc_params(
497499
.where(DataCollectionGroup.tag == proc_params.tag)
498500
.where(DataCollection.tag == proc_params.tilt_series_tag)
499501
.where(DataCollection.dcg_id == DataCollectionGroup.id)
502+
.where(DataCollection.dcg_tag == DataCollectionGroup.tag)
500503
.where(ProcessingJob.dc_id == DataCollection.id)
501504
.where(AutoProcProgram.pj_id == ProcessingJob.id)
502505
.where(ProcessingJob.recipe == "em-tomo-preprocess")
@@ -551,6 +554,7 @@ def register_tomo_proc_params(
551554
.where(DataCollectionGroup.tag == proc_params.tag)
552555
.where(DataCollection.tag == proc_params.tilt_series_tag)
553556
.where(DataCollection.dcg_id == DataCollectionGroup.id)
557+
.where(DataCollection.dcg_tag == DataCollectionGroup.tag)
554558
.where(ProcessingJob.dc_id == DataCollection.id)
555559
.where(AutoProcProgram.pj_id == ProcessingJob.id)
556560
.where(ProcessingJob.recipe == "em-tomo-preprocess")
@@ -943,6 +947,7 @@ def flush_spa_processing(
943947
.where(DataCollectionGroup.session_id == session_id)
944948
.where(DataCollectionGroup.tag == tag.tag)
945949
.where(DataCollection.dcg_id == DataCollectionGroup.id)
950+
.where(DataCollection.dcg_tag == DataCollectionGroup.tag)
946951
.where(ProcessingJob.dc_id == DataCollection.id)
947952
.where(AutoProcProgram.pj_id == ProcessingJob.id)
948953
.where(ProcessingJob.recipe == "em-spa-preprocess")
@@ -1073,6 +1078,7 @@ async def request_spa_preprocessing(
10731078
.where(DataCollectionGroup.session_id == session_id)
10741079
.where(DataCollectionGroup.tag == proc_file.tag)
10751080
.where(DataCollection.dcg_id == DataCollectionGroup.id)
1081+
.where(DataCollection.dcg_tag == DataCollectionGroup.tag)
10761082
.where(ProcessingJob.dc_id == DataCollection.id)
10771083
.where(AutoProcProgram.pj_id == ProcessingJob.id)
10781084
.where(ProcessingJob.recipe == "em-spa-preprocess")
@@ -1109,6 +1115,7 @@ async def request_spa_preprocessing(
11091115
)
11101116
.where(DataCollectionGroup.tag == proc_file.tag)
11111117
.where(DataCollection.dcg_id == DataCollectionGroup.id)
1118+
.where(DataCollection.dcg_tag == DataCollectionGroup.tag)
11121119
.where(ProcessingJob.dc_id == DataCollection.id)
11131120
.where(AutoProcProgram.pj_id == ProcessingJob.id)
11141121
.where(ProcessingJob.recipe == "em-spa-preprocess")
@@ -1230,6 +1237,7 @@ async def request_tomography_preprocessing(
12301237
select(DataCollectionGroup, DataCollection, ProcessingJob, AutoProcProgram)
12311238
.where(DataCollectionGroup.session_id == session_id)
12321239
.where(DataCollectionGroup.id == DataCollection.dcg_id)
1240+
.where(DataCollectionGroup.tag == DataCollection.dcg_tag)
12331241
.where(DataCollection.tag == proc_file.tag)
12341242
.where(ProcessingJob.dc_id == DataCollection.id)
12351243
.where(AutoProcProgram.pj_id == ProcessingJob.id)
@@ -1656,6 +1664,7 @@ def remove_session(client_id: int, db=murfey_db):
16561664
select(DataCollectionGroup, DataCollection, ProcessingJob)
16571665
.where(DataCollectionGroup.session_id == session_id)
16581666
.where(DataCollection.dcg_id == DataCollectionGroup.id)
1667+
.where(DataCollection.dcg_tag == DataCollectionGroup.tag)
16591668
.where(ProcessingJob.dc_id == DataCollection.id)
16601669
).all()
16611670
for c in collected_ids:

src/murfey/util/db.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import List, Optional
77

88
import sqlalchemy
9-
from sqlmodel import Field, Relationship, SQLModel, create_engine
9+
from sqlmodel import Field, Relationship, SQLModel, UniqueConstraint, create_engine
1010

1111
"""
1212
GENERAL
@@ -348,6 +348,8 @@ class Tilt(SQLModel, table=True): # type: ignore
348348

349349

350350
class DataCollectionGroup(SQLModel, table=True): # type: ignore
351+
__table_args__ = (UniqueConstraint("id", "tag", name="dcg_constraint"),)
352+
351353
id: int = Field(primary_key=True)
352354
session_id: int = Field(foreign_key="session.id", primary_key=True)
353355
tag: str = Field(primary_key=True)
@@ -372,6 +374,7 @@ class DataCollection(SQLModel, table=True): # type: ignore
372374
id: int = Field(primary_key=True, unique=True)
373375
tag: str = Field(primary_key=True)
374376
dcg_id: int = Field(foreign_key="datacollectiongroup.id")
377+
dcg_tag: str = Field(foreign_key="datacollectiongroup.tag")
375378
data_collection_group: Optional[DataCollectionGroup] = Relationship(
376379
back_populates="data_collections"
377380
)

0 commit comments

Comments
 (0)