Skip to content

Commit

Permalink
feat: Make email ID's case insensitive (#5728)
Browse files Browse the repository at this point in the history
* Database migration for deleting upper case emails and using email as an index

* Database migration to update deleted_at time
for repeated emails

* Updated migration

* Updated migrations

* Correct sql query.

* Sql query to undelete users
  • Loading branch information
prateekj117 authored and iamareebjamal committed Apr 13, 2019
1 parent 73f2f39 commit cd1caa4
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions migrations/versions/7bb5891a9f2e_lowercase_email.py
@@ -0,0 +1,35 @@
"""lowercase_email
Revision ID: 7bb5891a9f2e
Revises: 6e5c574cbfb8
Create Date: 2019-03-30 12:51:48.134800
"""

from alembic import op
from sqlalchemy import func
import sqlalchemy as sa
import sqlalchemy_utils


# revision identifiers, used by Alembic.
revision = '7bb5891a9f2e'
down_revision = '6e5c574cbfb8'


def upgrade():
op.execute("UPDATE users SET deleted_at = current_timestamp, _email = concat(_email, '_') where _email not in (SELECT DISTINCT ON (upper(_email)) _email FROM users);",
execution_options=None)
op.execute("create extension citext;",
execution_options=None)
op.execute("alter table users alter column _email type citext;",
execution_options=None)


def downgrade():
op.execute("alter table users alter column _email type text;",
execution_options=None)
op.execute("UPDATE users SET deleted_at = null, _email = left(_email, length(_email)-1) where right(_email, 1) = '_';",
execution_options=None)
op.execute("drop extension citext;",
execution_options=None)

0 comments on commit cd1caa4

Please sign in to comment.