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
Expand Up @@ -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),
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

The migration creates thing_id as nullable, but the model in db/nma_legacy.py defines it as nullable=False. This inconsistency means existing NULL values from the migration will violate the model constraint. Either update the model to allow NULL values or add a data migration step to populate NULL values before enforcing the NOT NULL constraint.

Copilot uses AI. Check for mistakes.
)

existing_fks = {
Expand Down
2 changes: 1 addition & 1 deletion db/nma_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class ChemistrySampleInfo(Base):
"SamplePointID", String(10), nullable=False
)

# FK to Thing - required (no orphans)
# FK to Thing - required for all ChemistrySampleInfo records
thing_id: Mapped[int] = mapped_column(
Integer, ForeignKey("thing.id", ondelete="CASCADE"), nullable=False
)
Expand Down
Loading