from alembic import op
import sqlalchemy as sa


revision = '0313_email_access_validated_at'
down_revision = '0312_populate_returned_letters'


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('users', sa.Column('email_access_validated_at', sa.DateTime(), nullable=True))
    # 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
    """)
    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.drop_column('users', 'email_access_validated_at')
    # ### end Alembic commands ###

from alembic import op
import sqlalchemy as sa


revision = '0313_email_access_validated_at'
down_revision = '0312_populate_returned_letters'


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('users', sa.Column('email_access_validated_at', sa.DateTime(), nullable=True))
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('users', 'email_access_validated_at')
    # ### end Alembic commands ###

Simplify the first migration, we will do execute statements later
Simplify the first migration, we will do execute statements later

  from alembic import op
  import sqlalchemy as sa
  
  
  revision = '0313_email_access_validated_at'
  down_revision = '0312_populate_returned_letters'
  
  
  def upgrade():
      # ### commands auto generated by Alembic - please adjust! ###
      op.add_column('users', sa.Column('email_access_validated_at', sa.DateTime(), nullable=True))
-     # 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
-     """)
-     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.drop_column('users', 'email_access_validated_at')
      # ### end Alembic commands ###
  
Simplify the first migration, we will do execute statements later
## Code Before:
from alembic import op
import sqlalchemy as sa


revision = '0313_email_access_validated_at'
down_revision = '0312_populate_returned_letters'


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('users', sa.Column('email_access_validated_at', sa.DateTime(), nullable=True))
    # 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
    """)
    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.drop_column('users', 'email_access_validated_at')
    # ### end Alembic commands ###

## Instruction:
Simplify the first migration, we will do execute statements later
## Code After:
from alembic import op
import sqlalchemy as sa


revision = '0313_email_access_validated_at'
down_revision = '0312_populate_returned_letters'


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('users', sa.Column('email_access_validated_at', sa.DateTime(), nullable=True))
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('users', 'email_access_validated_at')
    # ### end Alembic commands ###
