fix(db): make migrations and glossary index SQLite-compatible
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m57s

This commit is contained in:
2026-06-14 19:01:07 +02:00
parent cb8ce697d2
commit adc3583358
6 changed files with 93 additions and 35 deletions

View File

@@ -12,20 +12,38 @@ depends_on = None
def upgrade() -> None:
op.execute(
"ALTER TABLE users DROP CONSTRAINT IF EXISTS ck_users_tier"
)
op.execute(
"ALTER TABLE users ADD CONSTRAINT ck_users_tier "
"CHECK (tier IN ('free', 'starter', 'pro', 'business', 'enterprise'))"
)
conn = op.get_bind()
dialect = conn.dialect.name
if dialect == "sqlite":
# Migration 002 skipped the CHECK constraint on SQLite; just create it now.
with op.batch_alter_table("users") as batch_op:
batch_op.create_check_constraint(
"ck_users_tier",
"tier IN ('free', 'starter', 'pro', 'business', 'enterprise')",
)
else:
op.execute("ALTER TABLE users DROP CONSTRAINT IF EXISTS ck_users_tier")
op.execute(
"ALTER TABLE users ADD CONSTRAINT ck_users_tier "
"CHECK (tier IN ('free', 'starter', 'pro', 'business', 'enterprise'))"
)
def downgrade() -> None:
op.execute(
"ALTER TABLE users DROP CONSTRAINT IF EXISTS ck_users_tier"
)
op.execute(
"ALTER TABLE users ADD CONSTRAINT ck_users_tier "
"CHECK (tier IN ('free', 'pro'))"
)
conn = op.get_bind()
dialect = conn.dialect.name
if dialect == "sqlite":
with op.batch_alter_table("users") as batch_op:
batch_op.drop_constraint("ck_users_tier", type_="check")
batch_op.create_check_constraint(
"ck_users_tier",
"tier IN ('free', 'pro')",
)
else:
op.execute("ALTER TABLE users DROP CONSTRAINT IF EXISTS ck_users_tier")
op.execute(
"ALTER TABLE users ADD CONSTRAINT ck_users_tier "
"CHECK (tier IN ('free', 'pro'))"
)