fix: use raw SQL for enum creation in migrations 019/020 to avoid SQLAlchemy double-create
This commit is contained in:
parent
198170d999
commit
b9f042f400
2 changed files with 6 additions and 15 deletions
|
|
@ -16,13 +16,8 @@ depends_on = None
|
|||
|
||||
|
||||
def upgrade() -> None:
|
||||
# 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)
|
||||
# Create enum via raw SQL to avoid SQLAlchemy's double-creation issue
|
||||
op.execute("CREATE TYPE highlight_status AS ENUM ('candidate', 'approved', 'rejected')")
|
||||
|
||||
op.create_table(
|
||||
"highlight_candidates",
|
||||
|
|
@ -32,7 +27,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", hl_col_type, nullable=False, server_default="candidate"),
|
||||
sa.Column("status", sa.Enum("candidate", "approved", "rejected", name="highlight_status", create_type=False), 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),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -15,16 +15,12 @@ depends_on = None
|
|||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Create the chapter_status enum type
|
||||
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)
|
||||
# Create enum via raw SQL to avoid SQLAlchemy's double-creation issue
|
||||
op.execute("CREATE TYPE chapter_status AS ENUM ('draft', 'approved', 'hidden')")
|
||||
|
||||
op.add_column(
|
||||
"key_moments",
|
||||
sa.Column("chapter_status", ch_col_type, nullable=False, server_default="draft"),
|
||||
sa.Column("chapter_status", sa.Enum("draft", "approved", "hidden", name="chapter_status", create_type=False), nullable=False, server_default="draft"),
|
||||
)
|
||||
op.add_column(
|
||||
"key_moments",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue