kitchen/backend/migrations/add_supplier_skip_dext.py
jtricerolph bc874ac9ff Fix migration transaction poisoning: ADD COLUMN IF NOT EXISTS
Migrations used try/except around ADD COLUMN inside a single engine.begin()
block. When a 'column already exists' error was caught, asyncpg left the
transaction in aborted state, causing all subsequent DDL in the block to fail
with InFailedSQLTransactionError. Replace with IF NOT EXISTS to prevent the
error entirely.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-12 19:53:26 +00:00

30 lines
909 B
Python

"""
Migration: Add skip_dext column to suppliers table
"""
import asyncio
from sqlalchemy import text
from database import engine
async def migrate():
async with engine.begin() as conn:
# Add skip_dext column to suppliers table
try:
await conn.execute(text(
"""
ALTER TABLE suppliers
ADD COLUMN IF NOT EXISTS skip_dext BOOLEAN NOT NULL DEFAULT FALSE
"""
))
print("✓ Added skip_dext column to suppliers table")
except Exception as e:
if "already exists" in str(e).lower() or "duplicate column" in str(e).lower():
print("- skip_dext column already exists, skipping")
else:
raise
if __name__ == "__main__":
print("Running migration: add_supplier_skip_dext")
asyncio.run(migrate())
print("Migration complete!")