"""revision

Revision ID: 7c54be25e03c
Revises: 
Create Date: 2021-07-09 22:13:29.834378

"""
from alembic import op
import sqlalchemy as sa


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


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('account',
    sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
    sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('fullname', sa.String(length=50), nullable=True),
    sa.Column('email', sa.String(length=200), nullable=True),
    sa.Column('phone', sa.String(length=200), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_account_email'), 'account', ['email'], unique=True)
    op.create_index(op.f('ix_account_fullname'), 'account', ['fullname'], unique=False)
    op.create_index(op.f('ix_account_id'), 'account', ['id'], unique=False)
    op.create_index(op.f('ix_account_phone'), 'account', ['phone'], unique=True)
    op.create_table('role',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('guid', sa.String(length=100), nullable=True),
    sa.Column('name', sa.Enum('customer', 'admin', name='roles'), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_role_guid'), 'role', ['guid'], unique=True)
    op.create_index(op.f('ix_role_id'), 'role', ['id'], unique=False)
    op.create_index(op.f('ix_role_name'), 'role', ['name'], unique=True)
    op.create_table('account_role',
    sa.Column('account_id', sa.Integer(), nullable=True),
    sa.Column('role_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['account_id'], ['account.id'], ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['role_id'], ['role.id'], ondelete='CASCADE')
    )
    op.create_table('auth_data',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('login', sa.String(length=200), nullable=True),
    sa.Column('_password', sa.String(length=200), nullable=True),
    sa.Column('registration_type', sa.Enum('forms', 'phone', 'social', name='registrationtypes'), nullable=False),
    sa.Column('confirmed_at', sa.DateTime(), nullable=True),
    sa.Column('account_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['account_id'], ['account.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_auth_data_id'), 'auth_data', ['id'], unique=False)
    op.create_index(op.f('ix_auth_data_login'), 'auth_data', ['login'], unique=False)
    op.create_index(op.f('ix_auth_data_registration_type'), 'auth_data', ['registration_type'], unique=False)
    op.create_table('socials',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('social_type', sa.Enum('vk', 'google', 'facebook', name='socialtypes'), nullable=False),
    sa.Column('external_id', sa.String(length=100), nullable=True),
    sa.Column('auth_data_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['auth_data_id'], ['auth_data.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_socials_external_id'), 'socials', ['external_id'], unique=False)
    op.create_index(op.f('ix_socials_id'), 'socials', ['id'], unique=False)
    op.create_index(op.f('ix_socials_social_type'), 'socials', ['social_type'], unique=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_socials_social_type'), table_name='socials')
    op.drop_index(op.f('ix_socials_id'), table_name='socials')
    op.drop_index(op.f('ix_socials_external_id'), table_name='socials')
    op.drop_table('socials')
    op.drop_index(op.f('ix_auth_data_registration_type'), table_name='auth_data')
    op.drop_index(op.f('ix_auth_data_login'), table_name='auth_data')
    op.drop_index(op.f('ix_auth_data_id'), table_name='auth_data')
    op.drop_table('auth_data')
    op.drop_table('account_role')
    op.drop_index(op.f('ix_role_name'), table_name='role')
    op.drop_index(op.f('ix_role_id'), table_name='role')
    op.drop_index(op.f('ix_role_guid'), table_name='role')
    op.drop_table('role')
    op.drop_index(op.f('ix_account_phone'), table_name='account')
    op.drop_index(op.f('ix_account_id'), table_name='account')
    op.drop_index(op.f('ix_account_fullname'), table_name='account')
    op.drop_index(op.f('ix_account_email'), table_name='account')
    op.drop_table('account')
    # ### end Alembic commands ###
