From 158def46c5ee417bbb0729ea58d6ed808f51bab9 Mon Sep 17 00:00:00 2001 From: jross Date: Tue, 13 Jan 2026 16:04:57 -0700 Subject: [PATCH 1/2] feat: update thing_id foreign key in NMA_Chemistry_SampleInfo to allow legacy orphans --- .../95d8b982cd5d_add_nma_chemistry_lineage_relations.py | 4 ++-- db/nma_legacy.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/alembic/versions/95d8b982cd5d_add_nma_chemistry_lineage_relations.py b/alembic/versions/95d8b982cd5d_add_nma_chemistry_lineage_relations.py index b6b2b213f..c9f6a79e3 100644 --- a/alembic/versions/95d8b982cd5d_add_nma_chemistry_lineage_relations.py +++ b/alembic/versions/95d8b982cd5d_add_nma_chemistry_lineage_relations.py @@ -29,10 +29,10 @@ def upgrade() -> None: inspector = inspect(bind) columns = {col["name"] for col in inspector.get_columns("NMA_Chemistry_SampleInfo")} if "thing_id" not in columns: - # Add thing_id FK to NMA_Chemistry_SampleInfo (NOT NULL - no orphans) + # Add thing_id FK to NMA_Chemistry_SampleInfo (nullable to allow legacy orphans) op.add_column( "NMA_Chemistry_SampleInfo", - sa.Column("thing_id", sa.Integer(), nullable=False), + sa.Column("thing_id", sa.Integer(), nullable=True), ) existing_fks = { diff --git a/db/nma_legacy.py b/db/nma_legacy.py index 14cd9b728..729852d9a 100644 --- a/db/nma_legacy.py +++ b/db/nma_legacy.py @@ -173,9 +173,9 @@ class ChemistrySampleInfo(Base): "SamplePointID", String(10), nullable=False ) - # FK to Thing - required (no orphans) - thing_id: Mapped[int] = mapped_column( - Integer, ForeignKey("thing.id", ondelete="CASCADE"), nullable=False + # FK to Thing - nullable for legacy orphans + thing_id: Mapped[Optional[int]] = mapped_column( + Integer, ForeignKey("thing.id", ondelete="CASCADE"), nullable=True ) collection_date: Mapped[Optional[datetime]] = mapped_column( From 3edb1b59740ed10286cc6f1f999b8b079aeda577 Mon Sep 17 00:00:00 2001 From: Jake Ross Date: Tue, 13 Jan 2026 16:06:33 -0700 Subject: [PATCH 2/2] Update db/nma_legacy.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- db/nma_legacy.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/nma_legacy.py b/db/nma_legacy.py index 729852d9a..053276af0 100644 --- a/db/nma_legacy.py +++ b/db/nma_legacy.py @@ -173,9 +173,9 @@ class ChemistrySampleInfo(Base): "SamplePointID", String(10), nullable=False ) - # FK to Thing - nullable for legacy orphans - thing_id: Mapped[Optional[int]] = mapped_column( - Integer, ForeignKey("thing.id", ondelete="CASCADE"), nullable=True + # FK to Thing - required for all ChemistrySampleInfo records + thing_id: Mapped[int] = mapped_column( + Integer, ForeignKey("thing.id", ondelete="CASCADE"), nullable=False ) collection_date: Mapped[Optional[datetime]] = mapped_column(