"""initial

Revision ID: d61d756fe8f8
Revises: 
Create Date: 2021-01-17 21:40:44.781173

"""
from alembic import op
import sqlalchemy as sa
import alvinchow_backend.db.types
from alvinchow_backend.db.types import Text   # this is just for custom JSONB Alembic bug, remove if not needed


# revision identifiers, used by Alembic.
revision = 'd61d756fe8f8'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_next_bigint_id_function()
    op.create_table('user',
    sa.Column('created_at', alvinchow_backend.db.types.UTCDateTime(timezone=True), nullable=True),
    sa.Column('updated_at', alvinchow_backend.db.types.UTCDateTime(timezone=True), nullable=True),
    sa.Column('id', alvinchow_backend.db.types.BigIntegerID(), nullable=False),
    sa.Column('email', alvinchow_backend.db.types.Text(), nullable=True),
    sa.Column('email_verified_at', alvinchow_backend.db.types.UTCDateTime(timezone=True), nullable=True),
    sa.Column('password', alvinchow_backend.db.types.Text(), nullable=True),
    sa.Column('password_updated_at', alvinchow_backend.db.types.UTCDateTime(timezone=True), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.Column('last_login_time', alvinchow_backend.db.types.UTCDateTime(timezone=True), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.execute('ALTER TABLE "user" ALTER COLUMN id set default next_bigint_id(\'user_id_seq\')')
    op.create_index('ix_user_email_unique', 'user', ['email'], unique=True, postgresql_where=sa.text('email_verified_at IS NOT NULL'))
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('ix_user_email_unique', table_name='user')
    op.drop_table('user')
    op.drop_next_bigint_id_function()
    # ### end Alembic commands ###
