diff --git a/alembic/versions/0030_nullable_post_source_id_denorm_artist_id.py b/alembic/versions/0030_nullable_post_source_id_denorm_artist_id.py
index 150ba1b..c37e499 100644
--- a/alembic/versions/0030_nullable_post_source_id_denorm_artist_id.py
+++ b/alembic/versions/0030_nullable_post_source_id_denorm_artist_id.py
@@ -50,12 +50,14 @@ def upgrade() -> None:
conn = op.get_bind()
# Step 1: add Post.artist_id, initially nullable for backfill.
+ # FK naming follows the Base.metadata naming_convention
+ # (fk_
__) — alembic 0001 set this up.
op.add_column(
"post",
sa.Column("artist_id", sa.Integer, nullable=True),
)
op.create_foreign_key(
- "post_artist_id_fkey", "post", "artist",
+ "fk_post_artist_id_artist", "post", "artist",
["artist_id"], ["id"], ondelete="CASCADE",
)
@@ -82,22 +84,24 @@ def upgrade() -> None:
op.alter_column("post", "artist_id", nullable=False)
op.create_index("ix_post_artist_id", "post", ["artist_id"])
- # Step 4: relax post.source_id + flip FK to SET NULL.
+ # Step 4: relax post.source_id + flip FK to SET NULL. The original FK
+ # name from alembic 0001 is `fk_post_source_id_source` per the
+ # NAMING_CONVENTION in models/base.py.
op.alter_column("post", "source_id", nullable=True)
- op.drop_constraint("post_source_id_fkey", "post", type_="foreignkey")
+ op.drop_constraint("fk_post_source_id_source", "post", type_="foreignkey")
op.create_foreign_key(
- "post_source_id_fkey", "post", "source",
+ "fk_post_source_id_source", "post", "source",
["source_id"], ["id"], ondelete="SET NULL",
)
# Step 5: relax image_provenance.source_id + flip FK to SET NULL.
op.alter_column("image_provenance", "source_id", nullable=True)
op.drop_constraint(
- "image_provenance_source_id_fkey", "image_provenance",
+ "fk_image_provenance_source_id_source", "image_provenance",
type_="foreignkey",
)
op.create_foreign_key(
- "image_provenance_source_id_fkey", "image_provenance", "source",
+ "fk_image_provenance_source_id_source", "image_provenance", "source",
["source_id"], ["id"], ondelete="SET NULL",
)