<reponame>chaseste/fin4dummy
"""Initial migration.

Revision ID: d14c7a3fd28c
Revises: 
Create Date: 2020-09-14 15:05:59.119149

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.engine.reflection import Inspector


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


def upgrade():
    table_names = Inspector.from_engine(op.get_bind()).get_table_names()
    if "users" in table_names:
        return

    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('users',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('username', sa.String(length=64), nullable=False),
    sa.Column('first_name', sa.String(length=50), nullable=False),
    sa.Column('last_name', sa.String(length=50), nullable=False),
    sa.Column('email', sa.String(length=320), nullable=False),
    sa.Column('hash', sa.Text(), nullable=False),
    sa.Column('cash', sa.Float(precision='12,2'), nullable=False),
    sa.Column('verify_ind', sa.SmallInteger(), nullable=False),
    sa.Column('verify_dt_tm', sa.Text(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_users_id'), 'users', ['id'], unique=False)
    op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
    op.create_table('balances',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('value', sa.Float(precision='12,2'), nullable=False),
    sa.Column('bal_dt_tm', sa.Text(), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_balances_id'), 'balances', ['id'], unique=False)
    op.create_index(op.f('ix_balances_user_id'), 'balances', ['user_id'], unique=False)
    op.create_table('closed_positions',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('symbol', sa.String(length=6), nullable=False),
    sa.Column('shares', sa.Integer(), nullable=False),
    sa.Column('pps', sa.Float(precision='12,2'), nullable=False),
    sa.Column('price', sa.Float(precision='12,2'), nullable=False),
    sa.Column('close_dt_tm', sa.Text(), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_closed_positions_id'), 'closed_positions', ['id'], unique=False)
    op.create_index(op.f('ix_closed_positions_user_id'), 'closed_positions', ['user_id'], unique=False)
    op.create_table('holdings',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('symbol', sa.String(length=6), nullable=False),
    sa.Column('shares', sa.Integer(), nullable=False),
    sa.Column('price', sa.Float(precision='12,2'), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_holdings_id'), 'holdings', ['id'], unique=False)
    op.create_index(op.f('ix_holdings_user_id'), 'holdings', ['user_id'], unique=False)
    op.create_table('transacted',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('type', sa.String(length=5), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('name', sa.Text(), nullable=False),
    sa.Column('symbol', sa.String(length=6), nullable=False),
    sa.Column('shares', sa.Integer(), nullable=False),
    sa.Column('price', sa.Float(precision='12,2'), nullable=False),
    sa.Column('cost', sa.Float(precision='12,2'), nullable=False),
    sa.Column('trans_dt_tm', sa.Text(), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_transacted_id'), 'transacted', ['id'], unique=False)
    op.create_index(op.f('ix_transacted_user_id'), 'transacted', ['user_id'], unique=False)
    op.create_table('two_factor_auth',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('auth_flag', sa.SmallInteger(), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_two_factor_auth_id'), 'two_factor_auth', ['id'], unique=False)
    op.create_index(op.f('ix_two_factor_auth_user_id'), 'two_factor_auth', ['user_id'], unique=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_two_factor_auth_user_id'), table_name='two_factor_auth')
    op.drop_index(op.f('ix_two_factor_auth_id'), table_name='two_factor_auth')
    op.drop_table('two_factor_auth')
    op.drop_index(op.f('ix_transacted_user_id'), table_name='transacted')
    op.drop_index(op.f('ix_transacted_id'), table_name='transacted')
    op.drop_table('transacted')
    op.drop_index(op.f('ix_holdings_user_id'), table_name='holdings')
    op.drop_index(op.f('ix_holdings_id'), table_name='holdings')
    op.drop_table('holdings')
    op.drop_index(op.f('ix_closed_positions_user_id'), table_name='closed_positions')
    op.drop_index(op.f('ix_closed_positions_id'), table_name='closed_positions')
    op.drop_table('closed_positions')
    op.drop_index(op.f('ix_balances_user_id'), table_name='balances')
    op.drop_index(op.f('ix_balances_id'), table_name='balances')
    op.drop_table('balances')
    op.drop_index(op.f('ix_users_username'), table_name='users')
    op.drop_index(op.f('ix_users_id'), table_name='users')
    op.drop_table('users')
    # ### end Alembic commands ###

"""Initial migration.

Revision ID: d14c7a3fd28c
Revises: 
Create Date: 2020-09-14 15:05:59.119149

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.engine.reflection import Inspector


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


def upgrade():
    table_names = Inspector.from_engine(op.get_bind()).get_table_names()
    if "users" in table_names:
        return

    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('users',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('username', sa.String(length=64), nullable=False),
    sa.Column('first_name', sa.String(length=50), nullable=False),
    sa.Column('last_name', sa.String(length=50), nullable=False),
    sa.Column('email', sa.String(length=320), nullable=False),
    sa.Column('hash', sa.Text(), nullable=False),
    sa.Column('cash', sa.Float(precision='12,2'), nullable=False),
    sa.Column('verify_ind', sa.SmallInteger(), nullable=False),
    sa.Column('verify_dt_tm', sa.Text(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_users_id'), 'users', ['id'], unique=False)
    op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
    op.create_table('balances',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('value', sa.Float(precision='12,2'), nullable=False),
    sa.Column('bal_dt_tm', sa.Text(), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_balances_id'), 'balances', ['id'], unique=False)
    op.create_index(op.f('ix_balances_user_id'), 'balances', ['user_id'], unique=False)
    op.create_table('closed_positions',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('symbol', sa.String(length=6), nullable=False),
    sa.Column('shares', sa.Integer(), nullable=False),
    sa.Column('pps', sa.Float(precision='12,2'), nullable=False),
    sa.Column('price', sa.Float(precision='12,2'), nullable=False),
    sa.Column('close_dt_tm', sa.Text(), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_closed_positions_id'), 'closed_positions', ['id'], unique=False)
    op.create_index(op.f('ix_closed_positions_user_id'), 'closed_positions', ['user_id'], unique=False)
    op.create_table('holdings',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('symbol', sa.String(length=6), nullable=False),
    sa.Column('shares', sa.Integer(), nullable=False),
    sa.Column('price', sa.Float(precision='12,2'), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_holdings_id'), 'holdings', ['id'], unique=False)
    op.create_index(op.f('ix_holdings_user_id'), 'holdings', ['user_id'], unique=False)
    op.create_table('transacted',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('type', sa.String(length=5), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('name', sa.Text(), nullable=False),
    sa.Column('symbol', sa.String(length=6), nullable=False),
    sa.Column('shares', sa.Integer(), nullable=False),
    sa.Column('price', sa.Float(precision='12,2'), nullable=False),
    sa.Column('cost', sa.Float(precision='12,2'), nullable=False),
    sa.Column('trans_dt_tm', sa.Text(), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_transacted_id'), 'transacted', ['id'], unique=False)
    op.create_index(op.f('ix_transacted_user_id'), 'transacted', ['user_id'], unique=False)
    op.create_table('two_factor_auth',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('auth_flag', sa.SmallInteger(), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_two_factor_auth_id'), 'two_factor_auth', ['id'], unique=False)
    op.create_index(op.f('ix_two_factor_auth_user_id'), 'two_factor_auth', ['user_id'], unique=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_two_factor_auth_user_id'), table_name='two_factor_auth')
    op.drop_index(op.f('ix_two_factor_auth_id'), table_name='two_factor_auth')
    op.drop_table('two_factor_auth')
    op.drop_index(op.f('ix_transacted_user_id'), table_name='transacted')
    op.drop_index(op.f('ix_transacted_id'), table_name='transacted')
    op.drop_table('transacted')
    op.drop_index(op.f('ix_holdings_user_id'), table_name='holdings')
    op.drop_index(op.f('ix_holdings_id'), table_name='holdings')
    op.drop_table('holdings')
    op.drop_index(op.f('ix_closed_positions_user_id'), table_name='closed_positions')
    op.drop_index(op.f('ix_closed_positions_id'), table_name='closed_positions')
    op.drop_table('closed_positions')
    op.drop_index(op.f('ix_balances_user_id'), table_name='balances')
    op.drop_index(op.f('ix_balances_id'), table_name='balances')
    op.drop_table('balances')
    op.drop_index(op.f('ix_users_username'), table_name='users')
    op.drop_index(op.f('ix_users_id'), table_name='users')
    op.drop_table('users')
    # ### end Alembic commands ###
Initial migration.  Revision ID: d14c7a3fd28c Revises:  Create Date: 2020-09-14 15:05:59.119149 # revision identifiers, used by Alembic. # ### commands auto generated by Alembic - please adjust! ### # ### end Alembic commands ### # ### commands auto generated by Alembic - please adjust! ### # ### end Alembic commands ###