Set unique constraints for email and mobile

This commit is contained in:
coolneng 2020-09-17 17:32:53 +02:00
parent 31e0a70845
commit 7573e9ab41
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,31 @@
"""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