Files
romm/backend/alembic/versions/0028_user_email.py
Georges-Antoine Assi 9a574e076a Add if_not_exists/if_exists guards to all alembic create_index/drop_index ops
Prevents errors when migrations are re-run against a database that
already has (or has already dropped) the target indexes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 23:04:08 -04:00

33 lines
892 B
Python

"""Add email to users table
Revision ID: 0028_user_email
Revises: 0027_platforms_data
Create Date: 2024-12-09 19:26:34.257411
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = "0028_user_email"
down_revision = "0027_platforms_data"
branch_labels = None
depends_on = None
def upgrade() -> None:
with op.batch_alter_table("users", schema=None) as batch_op:
batch_op.add_column(
sa.Column("email", sa.String(length=255), nullable=True), if_not_exists=True
)
batch_op.create_index(
batch_op.f("ix_users_email"), ["email"], unique=True, if_not_exists=True
)
def downgrade() -> None:
with op.batch_alter_table("users", schema=None) as batch_op:
batch_op.drop_index(batch_op.f("ix_users_email"), if_exists=True)
batch_op.drop_column("email", if_exists=True)