Skip to content

Commit 9655910

Browse files
committed
wip
1 parent b665bfa commit 9655910

File tree

4 files changed

+114
-198
lines changed

4 files changed

+114
-198
lines changed

docs/software-architecture.mermaid

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
graph LR
1+
graph TD
22
subgraph k8s["Kubernetes Cluster (Scientific Compute)"]
33
subgraph core["Core Services"]
44
api["SmartEM Core Service & API"]
@@ -44,4 +44,4 @@ graph LR
4444
class infrastructure infra
4545
class ext ext
4646
%% Link styling
47-
linkStyle 0,1,2,3,4,5,6,7,8 stroke:#666
47+
linkStyle 0,1,2,3,4,5,6,7,8 stroke:#666

src/smartem_decisions/http_api.py

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,11 @@ def delete_acquisition(acquisition_id: str, db: SqlAlchemySession = Depends(get_
241241
if not db_acquisition:
242242
raise HTTPException(status_code=404, detail="Acquisition not found")
243243

244-
# Publish the deletion event to RabbitMQ
244+
245245
success = publish_acquisition_deleted(acquisition_id)
246246
if not success:
247247
logger.error(f"Failed to publish acquisition deleted event for ID: {acquisition_id}")
248248

249-
# For immediate feedback, also delete from the database
250-
db.delete(db_acquisition)
251-
db.commit()
252-
253249
return None
254250

255251

@@ -307,15 +303,11 @@ def delete_grid(grid_id: str, db: SqlAlchemySession = Depends(get_db)):
307303
if not db_grid:
308304
raise HTTPException(status_code=404, detail="Grid not found")
309305

310-
# Publish the deletion event to RabbitMQ
306+
311307
success = publish_grid_deleted(grid_id)
312308
if not success:
313309
logger.error(f"Failed to publish grid deleted event for ID: {grid_id}")
314310

315-
# For immediate feedback, also delete from the database
316-
db.delete(db_grid)
317-
db.commit()
318-
319311
return None
320312

321313

@@ -405,15 +397,11 @@ def delete_atlas(atlas_id: str, db: SqlAlchemySession = Depends(get_db)):
405397
if not db_atlas:
406398
raise HTTPException(status_code=404, detail="Atlas not found")
407399

408-
# Publish the deletion event to RabbitMQ
400+
409401
success = publish_atlas_deleted(atlas_id)
410402
if not success:
411403
logger.error(f"Failed to publish atlas deleted event for ID: {atlas_id}")
412404

413-
# For immediate feedback, also delete from the database
414-
db.delete(db_atlas)
415-
db.commit()
416-
417405
return None
418406

419407

@@ -534,15 +522,11 @@ def delete_atlas_tile(tile_id: str, db: SqlAlchemySession = Depends(get_db)):
534522
if not db_tile:
535523
raise HTTPException(status_code=404, detail="Atlas tile not found")
536524

537-
# Publish the deletion event to RabbitMQ
525+
538526
success = publish_atlas_tile_deleted(tile_id)
539527
if not success:
540528
logger.error(f"Failed to publish atlas tile deleted event for ID: {tile_id}")
541529

542-
# For immediate feedback, also delete from the database
543-
db.delete(db_tile)
544-
db.commit()
545-
546530
return None
547531

548532

@@ -636,15 +620,11 @@ def delete_gridsquare(gridsquare_id: str, db: SqlAlchemySession = Depends(get_db
636620
if not db_gridsquare:
637621
raise HTTPException(status_code=404, detail="Grid Square not found")
638622

639-
# Publish the deletion event to RabbitMQ
623+
640624
success = publish_gridsquare_deleted(gridsquare_id)
641625
if not success:
642626
logger.error(f"Failed to publish grid square deleted event for ID: {gridsquare_id}")
643627

644-
# For immediate feedback, also delete from the database
645-
db.delete(db_gridsquare)
646-
db.commit()
647-
648628
return None
649629

650630

@@ -735,15 +715,11 @@ def delete_foilhole(foilhole_id: str, db: SqlAlchemySession = Depends(get_db)):
735715
if not db_foilhole:
736716
raise HTTPException(status_code=404, detail="Foil Hole not found")
737717

738-
# Publish the deletion event to RabbitMQ
718+
739719
success = publish_foilhole_deleted(foilhole_id)
740720
if not success:
741721
logger.error(f"Failed to publish foil hole deleted event for ID: {foilhole_id}")
742722

743-
# For immediate feedback, also delete from the database
744-
db.delete(db_foilhole)
745-
db.commit()
746-
747723
return None
748724

749725

@@ -837,15 +813,11 @@ def delete_micrograph(micrograph_id: str, db: SqlAlchemySession = Depends(get_db
837813
if not db_micrograph:
838814
raise HTTPException(status_code=404, detail="Micrograph not found")
839815

840-
# Publish the deletion event to RabbitMQ
816+
841817
success = publish_micrograph_deleted(micrograph_id)
842818
if not success:
843819
logger.error(f"Failed to publish micrograph deleted event for ID: {micrograph_id}")
844820

845-
# For immediate feedback, also delete from the database
846-
db.delete(db_micrograph)
847-
db.commit()
848-
849821
return None
850822

851823

@@ -879,7 +851,7 @@ def create_foilhole_micrograph(
879851
response_data = {
880852
"id": micrograph.id,
881853
"foilhole_id": foilhole_id,
882-
"status": MicrographStatus.NONE, # Set default status
854+
"status": MicrographStatus.NONE, # Set default status TODO surely set whatever status was provided by client?
883855
**micrograph.model_dump(),
884856
}
885857

src/smartem_decisions/model/database.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
class Acquisition(SQLModel, table=True, table_name="acquisition"):
3131
__table_args__ = {"extend_existing": True}
32-
id: str = Field(primary_key=True)
32+
uuid: str = Field(primary_key=True)
3333
epu_id: str | None = Field(default=None)
3434
name: str
3535
status: AcquisitionStatus = Field(default=AcquisitionStatus.PLANNED, sa_column=Column(AcquisitionStatusType()))
@@ -45,9 +45,9 @@ class Acquisition(SQLModel, table=True, table_name="acquisition"):
4545

4646
class Atlas(SQLModel, table=True, table_name="atlas"):
4747
__table_args__ = {"extend_existing": True}
48-
id: str = Field(primary_key=True)
48+
uuid: str = Field(primary_key=True)
4949
atlas_id: str = Field(default="")
50-
grid_id: str | None = Field(default=None, foreign_key="grid.id")
50+
grid_id: str | None = Field(default=None, foreign_key="grid.uuid")
5151
acquisition_date: datetime | None = Field(default=None)
5252
storage_folder: str | None = Field(default=None)
5353
description: str | None = Field(default=None)
@@ -60,8 +60,8 @@ class Atlas(SQLModel, table=True, table_name="atlas"):
6060

6161
class Grid(SQLModel, table=True, table_name="grid"):
6262
__table_args__ = {"extend_existing": True}
63-
id: str = Field(primary_key=True)
64-
acquisition_id: str | None = Field(default=None, foreign_key="acquisition.id")
63+
uuid: str = Field(primary_key=True)
64+
acquisition_id: str | None = Field(default=None, foreign_key="acquisition.uuid")
6565
status: GridStatus = Field(default=GridStatus.NONE, sa_column=Column(GridStatusType()))
6666
name: str
6767
data_dir: str | None = Field(default=None)
@@ -83,8 +83,8 @@ class Grid(SQLModel, table=True, table_name="grid"):
8383

8484
class AtlasTile(SQLModel, table=True, table_name="atlastile"):
8585
__table_args__ = {"extend_existing": True}
86-
id: str = Field(primary_key=True)
87-
atlas_id: str | None = Field(default=None, foreign_key="atlas.id")
86+
uuid: str = Field(primary_key=True)
87+
atlas_id: str | None = Field(default=None, foreign_key="atlas.uuid")
8888
tile_id: str = Field(default="")
8989
position_x: int | None = Field(default=None)
9090
position_y: int | None = Field(default=None)
@@ -97,8 +97,8 @@ class AtlasTile(SQLModel, table=True, table_name="atlastile"):
9797

9898
class GridSquare(SQLModel, table=True, table_name="gridsquare"):
9999
__table_args__ = {"extend_existing": True}
100-
id: str = Field(primary_key=True)
101-
grid_id: str | None = Field(default=None, foreign_key="grid.id")
100+
uuid: str = Field(primary_key=True)
101+
grid_id: str | None = Field(default=None, foreign_key="grid.uuid")
102102
status: GridSquareStatus = Field(default=GridSquareStatus.NONE, sa_column=Column(GridSquareStatusType()))
103103
gridsquare_id: str = Field(default="")
104104
data_dir: str | None = Field(default=None)
@@ -132,8 +132,8 @@ class GridSquare(SQLModel, table=True, table_name="gridsquare"):
132132

133133
class FoilHole(SQLModel, table=True, table_name="foilhole"):
134134
__table_args__ = {"extend_existing": True}
135-
id: str = Field(primary_key=True)
136-
gridsquare_id: str | None = Field(default=None, foreign_key="gridsquare.id")
135+
uuid: str = Field(primary_key=True)
136+
gridsquare_id: str | None = Field(default=None, foreign_key="gridsquare.uuid")
137137
status: FoilHoleStatus = Field(default=FoilHoleStatus.NONE, sa_column=Column(FoilHoleStatusType()))
138138
foilhole_id: str = Field(default="")
139139
center_x: float | None = Field(default=None)
@@ -157,8 +157,8 @@ class FoilHole(SQLModel, table=True, table_name="foilhole"):
157157

158158
class Micrograph(SQLModel, table=True, table_name="micrograph"):
159159
__table_args__ = {"extend_existing": True}
160-
id: str = Field(primary_key=True)
161-
foilhole_id: str | None = Field(default=None, foreign_key="foilhole.id")
160+
uuid: str = Field(primary_key=True)
161+
foilhole_id: str | None = Field(default=None, foreign_key="foilhole.uuid")
162162
status: MicrographStatus = Field(default=MicrographStatus.NONE, sa_column=Column(MicrographStatusType()))
163163
micrograph_id: str = Field(default="")
164164
location_id: str | None = Field(default=None)
@@ -199,7 +199,7 @@ class QualityPredictionModel(SQLModel, table=True):
199199
class QualityPredictionModelParameter(SQLModel, table=True):
200200
__table_args__ = {"extend_existing": True}
201201
id: int | None = Field(default=None, primary_key=True)
202-
grid_id: str = Field(foreign_key="grid.id")
202+
grid_id: str = Field(foreign_key="grid.uuid")
203203
timestamp: datetime = Field(default_factory=datetime.now)
204204
prediction_model_name: str = Field(foreign_key="qualitypredictionmodel.name")
205205
key: str
@@ -211,8 +211,8 @@ class QualityPredictionModelParameter(SQLModel, table=True):
211211
class QualityPredictionModelWeight(SQLModel, table=True):
212212
__table_args__ = {"extend_existing": True}
213213
id: int | None = Field(default=None, primary_key=True)
214-
grid_id: str = Field(foreign_key="grid.id")
215-
micrograph_id: str | None = Field(default=None, foreign_key="micrograph.id")
214+
grid_id: str = Field(foreign_key="grid.uuid")
215+
micrograph_id: str | None = Field(default=None, foreign_key="micrograph.uuid")
216216
micrograph_quality: bool | None = Field(default=None)
217217
timestamp: datetime = Field(default_factory=datetime.now)
218218
origin: str | None = Field(default=None)
@@ -229,8 +229,8 @@ class QualityPrediction(SQLModel, table=True):
229229
timestamp: datetime = Field(default_factory=datetime.now)
230230
value: float
231231
prediction_model_name: str = Field(foreign_key="qualitypredictionmodel.name")
232-
foilhole_id: str | None = Field(default=None, foreign_key="foilhole.id")
233-
gridsquare_id: str | None = Field(default=None, foreign_key="gridsquare.id")
232+
foilhole_id: str | None = Field(default=None, foreign_key="foilhole.uuid")
233+
gridsquare_id: str | None = Field(default=None, foreign_key="gridsquare.uuid")
234234
foilhole: FoilHole | None = Relationship(back_populates="prediction")
235235
gridsquare: GridSquare | None = Relationship(back_populates="prediction")
236236
model: QualityPredictionModel | None = Relationship(back_populates="predictions")
@@ -270,39 +270,39 @@ def _create_db_and_tables(engine):
270270
try:
271271
# acquisition indexes
272272
sess.execute(
273-
text("CREATE INDEX IF NOT EXISTS idx_acquisition_id_pattern ON acquisition (id text_pattern_ops);")
273+
text("CREATE INDEX IF NOT EXISTS idx_acquisition_id_pattern ON acquisition (uuid text_pattern_ops);")
274274
)
275-
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_acquisition_id_hash ON acquisition USING hash (id);"))
275+
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_acquisition_id_hash ON acquisition USING hash (uuid);"))
276276
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_acquisition_name ON acquisition (name);"))
277277

278278
# atlas indexes
279-
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_atlas_id_pattern ON atlas (id text_pattern_ops);"))
279+
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_atlas_id_pattern ON atlas (uuid text_pattern_ops);"))
280280
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_atlas_grid_id ON atlas (grid_id);"))
281281

282282
# grid indexes
283-
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_grid_id_pattern ON grid (id text_pattern_ops);"))
284-
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_grid_id_hash ON grid USING hash (id);"))
283+
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_grid_id_pattern ON grid (uuid text_pattern_ops);"))
284+
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_grid_id_hash ON grid USING hash (uuid);"))
285285
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_grid_acquisition_id ON grid (acquisition_id);"))
286286
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_grid_name ON grid (name);"))
287287

288288
# gridsquare indexes
289289
sess.execute(
290-
text("CREATE INDEX IF NOT EXISTS idx_gridsquare_id_pattern ON gridsquare (id text_pattern_ops);")
290+
text("CREATE INDEX IF NOT EXISTS idx_gridsquare_id_pattern ON gridsquare (uuid text_pattern_ops);")
291291
)
292-
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_gridsquare_id_hash ON gridsquare USING hash (id);"))
292+
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_gridsquare_id_hash ON gridsquare USING hash (uuid);"))
293293
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_gridsquare_grid_id ON gridsquare (grid_id);"))
294294

295295
# foilhole indexes
296-
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_foilhole_id_pattern ON foilhole (id text_pattern_ops);"))
297-
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_foilhole_id_hash ON foilhole USING hash (id);"))
296+
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_foilhole_id_pattern ON foilhole (uuid text_pattern_ops);"))
297+
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_foilhole_id_hash ON foilhole USING hash (uuid);"))
298298
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_foilhole_gridsquare_id ON foilhole (gridsquare_id);"))
299299
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_foilhole_quality ON foilhole (quality);"))
300300

301301
# micrograph indexes
302302
sess.execute(
303-
text("CREATE INDEX IF NOT EXISTS idx_micrograph_id_pattern ON micrograph (id text_pattern_ops);")
303+
text("CREATE INDEX IF NOT EXISTS idx_micrograph_id_pattern ON micrograph (uuid text_pattern_ops);")
304304
)
305-
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_micrograph_id_hash ON micrograph USING hash (id);"))
305+
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_micrograph_id_hash ON micrograph USING hash (uuid);"))
306306
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_micrograph_foilhole_id ON micrograph (foilhole_id);"))
307307

308308
sess.commit()
@@ -312,7 +312,7 @@ def _create_db_and_tables(engine):
312312

313313
try:
314314
sess.execute(
315-
text("CREATE INDEX IF NOT EXISTS idx_atlastile_id_pattern ON atlastile (id text_pattern_ops);")
315+
text("CREATE INDEX IF NOT EXISTS idx_atlastile_id_pattern ON atlastile (uuid text_pattern_ops);")
316316
)
317317
sess.execute(text("CREATE INDEX IF NOT EXISTS idx_atlastile_atlas_id ON atlastile (atlas_id);"))
318318
sess.commit()

0 commit comments

Comments
 (0)