Skip to content

Commit 81605ba

Browse files
kbighorseclaude
andcommitted
fix: add nma_pk_location to thing_version table
SQLAlchemy-continuum creates a thing_version table that mirrors the thing table structure. The migration must add the new column to both tables for versioning to work correctly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d9c151c commit 81605ba

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

alembic/versions/76e3ae8b99cb_enforce_thing_fk_for_nma_legacy_models.py

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

3030
def upgrade() -> None:
3131
"""Upgrade schema to enforce Thing FK relationships."""
32-
# 1. Add nma_pk_location column to thing table
32+
# 1. Add nma_pk_location column to thing table and its version table
3333
op.add_column(
3434
"thing",
3535
sa.Column(
@@ -39,6 +39,14 @@ def upgrade() -> None:
3939
comment="To audit the original NM_Aquifer LocationID if it was transferred over",
4040
),
4141
)
42+
op.add_column(
43+
"thing_version",
44+
sa.Column(
45+
"nma_pk_location",
46+
sa.String(),
47+
nullable=True,
48+
),
49+
)
4250

4351
# 2. Make thing_id NOT NULL on NMA_AssociatedData
4452
# First, delete any orphan records (records without a thing_id)
@@ -57,8 +65,9 @@ def upgrade() -> None:
5765

5866
def downgrade() -> None:
5967
"""Downgrade schema to allow nullable thing_id."""
60-
# 1. Remove nma_pk_location column from thing table
68+
# 1. Remove nma_pk_location column from thing table and its version table
6169
op.drop_column("thing", "nma_pk_location")
70+
op.drop_column("thing_version", "nma_pk_location")
6271

6372
# 2. Make thing_id nullable on NMA_AssociatedData
6473
op.alter_column(

0 commit comments

Comments
 (0)