mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 18:31:13 -05:00
Populate email_access_validated_at_column and make it non-nullable
This commit is contained in:
43
migrations/versions/0314_populate_email_access.py
Normal file
43
migrations/versions/0314_populate_email_access.py
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
"""
|
||||||
|
|
||||||
|
Revision ID: 0314_populate_email_access
|
||||||
|
Revises: 0313_email_access_validated_at
|
||||||
|
Create Date: 2020-01-31 10:35:44.524606
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
|
||||||
|
revision = '0314_populate_email_access'
|
||||||
|
down_revision = '0313_email_access_validated_at'
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
# if user has email_auth, set email_access_validated_at on last login, else set it at user created_at date.
|
||||||
|
op.execute("""
|
||||||
|
UPDATE
|
||||||
|
users
|
||||||
|
SET
|
||||||
|
email_access_validated_at = created_at
|
||||||
|
WHERE
|
||||||
|
email_access_validated_at IS NULL
|
||||||
|
""")
|
||||||
|
op.execute("""
|
||||||
|
UPDATE
|
||||||
|
users
|
||||||
|
SET
|
||||||
|
email_access_validated_at = logged_in_at
|
||||||
|
WHERE
|
||||||
|
auth_type = 'email_auth'
|
||||||
|
AND
|
||||||
|
logged_in_at IS NOT NULL
|
||||||
|
""")
|
||||||
|
op.alter_column('users', 'email_access_validated_at', nullable=False)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.alter_column('users', 'email_access_validated_at', nullable=True)
|
||||||
|
# ### end Alembic commands ###
|
||||||
Reference in New Issue
Block a user