Skip to content
Merged
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 @@ -50,6 +50,18 @@ def upgrade() -> None:
ondelete="CASCADE",
)

# Ensure SamplePtID is uniquely constrained for downstream FK usage.
pk = inspector.get_pk_constraint("NMA_Chemistry_SampleInfo")
pk_columns = pk.get("constrained_columns") or []
unique_constraints = inspector.get_unique_constraints("NMA_Chemistry_SampleInfo")
unique_columns = {tuple(uc.get("column_names") or []) for uc in unique_constraints}
if pk_columns != ["SamplePtID"] and ("SamplePtID",) not in unique_columns:
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 primary key check uses exact equality (pk_columns != ['SamplePtID']) which will fail if SamplePtID is part of a composite primary key. The condition should check if SamplePtID is in the primary key columns using 'SamplePtID' not in pk_columns instead of pk_columns != ['SamplePtID'].

Suggested change
if pk_columns != ["SamplePtID"] and ("SamplePtID",) not in unique_columns:
if "SamplePtID" not in pk_columns and ("SamplePtID",) not in unique_columns:

Copilot uses AI. Check for mistakes.
op.create_unique_constraint(
"NMA_Chemistry_SampleInfo_SamplePtID_key",
"NMA_Chemistry_SampleInfo",
["SamplePtID"],
Comment on lines +58 to +62

Choose a reason for hiding this comment

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

P2 Badge Drop new unique constraint on downgrade

The upgrade adds a new unique constraint on SamplePtID, but downgrade() never removes it. If this migration is rolled back, the schema will not return to its prior state and any older code or migrations that expect duplicates (or no uniqueness guarantee) can fail. Consider dropping NMA_Chemistry_SampleInfo_SamplePtID_key in downgrade() when it was created.

Useful? React with 👍 / 👎.

)

# Create NMA_MinorTraceChemistry table
op.create_table(
"NMA_MinorTraceChemistry",
Expand Down
Loading