diff --git a/alembic/versions/019_add_highlight_candidates.py b/alembic/versions/019_add_highlight_candidates.py index b4f1da5..f2b32ed 100644 --- a/alembic/versions/019_add_highlight_candidates.py +++ b/alembic/versions/019_add_highlight_candidates.py @@ -16,10 +16,14 @@ depends_on = None def upgrade() -> None: - # Create the highlight_status enum type + # Create the highlight_status enum type (create_type=False on the column + # prevents SQLAlchemy's before_create event from double-creating it) highlight_status = sa.Enum("candidate", "approved", "rejected", name="highlight_status", create_constraint=True) highlight_status.create(op.get_bind(), checkfirst=True) + # Use create_type=False so create_table doesn't try to recreate the enum + hl_col_type = sa.Enum("candidate", "approved", "rejected", name="highlight_status", create_type=False) + op.create_table( "highlight_candidates", sa.Column("id", UUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")), @@ -28,7 +32,7 @@ def upgrade() -> None: sa.Column("score", sa.Float, nullable=False), sa.Column("score_breakdown", sa.dialects.postgresql.JSONB, nullable=True), sa.Column("duration_secs", sa.Float, nullable=False), - sa.Column("status", highlight_status, nullable=False, server_default="candidate"), + sa.Column("status", hl_col_type, nullable=False, server_default="candidate"), sa.Column("created_at", sa.DateTime, server_default=sa.func.now(), nullable=False), sa.Column("updated_at", sa.DateTime, server_default=sa.func.now(), nullable=False), ) diff --git a/alembic/versions/020_add_chapter_status_and_sort_order.py b/alembic/versions/020_add_chapter_status_and_sort_order.py index b5b5d75..9a648ca 100644 --- a/alembic/versions/020_add_chapter_status_and_sort_order.py +++ b/alembic/versions/020_add_chapter_status_and_sort_order.py @@ -19,9 +19,12 @@ def upgrade() -> None: chapter_status = sa.Enum("draft", "approved", "hidden", name="chapter_status", create_constraint=True) chapter_status.create(op.get_bind(), checkfirst=True) + # Use create_type=False to prevent double-creation during add_column + ch_col_type = sa.Enum("draft", "approved", "hidden", name="chapter_status", create_type=False) + op.add_column( "key_moments", - sa.Column("chapter_status", chapter_status, nullable=False, server_default="draft"), + sa.Column("chapter_status", ch_col_type, nullable=False, server_default="draft"), ) op.add_column( "key_moments",