odapi/migrations/versions/9ee45f714f8b_set_unique_fie...

32 lines
705 B
Python
Raw Normal View History

"""set unique fields in users table
Revision ID: 9ee45f714f8b
Revises: 0a4f01e489de
Create Date: 2020-09-12 18:25:17.026880
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "9ee45f714f8b"
down_revision = "0a4f01e489de"
branch_labels = None
depends_on = None
def upgrade():
fields = ["email", "mobile"]
for item in fields:
query = "DELETE FROM users WHERE email = '' AND status = 0"
op.execute(query)
with op.batch_alter_table("users") as batch_op:
batch_op.create_unique_constraint(
constraint_name="uq_users_{}".format(item), columns=[item],
)
def downgrade():
pass