"""Initial Migration

Revision ID: f5e94f953ba2
Revises: 
Create Date: 2018-02-13 10:39:24.828811

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

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


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('lines',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('line_content', sa.String(length=200), nullable=True),
    sa.Column('pitch_id', sa.Integer(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['pitch_id'], ['pitches.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('comments',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('comment_content', sa.String(), nullable=True),
    sa.Column('line_id', sa.Integer(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['line_id'], ['lines.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.add_column('pitches', sa.Column('name', sa.String(length=255), nullable=True))
    op.drop_column('pitches', 'author')
    op.drop_column('pitches', 'category')
    op.drop_column('pitches', 'body')
    op.drop_column('pitches', 'downvotes')
    op.drop_column('pitches', 'title')
    op.drop_column('pitches', 'upvotes')
    op.drop_column('pitches', 'posted')
    op.add_column('users', sa.Column('pitch_id', sa.Integer(), nullable=True))
    op.drop_index('ix_users_username', table_name='users')
    op.create_foreign_key(None, 'users', 'pitches', ['pitch_id'], ['id'])
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'users', type_='foreignkey')
    op.create_index('ix_users_username', 'users', ['username'], unique=False)
    op.drop_column('users', 'pitch_id')
    op.add_column('pitches', sa.Column('posted', postgresql.TIMESTAMP(), autoincrement=False, nullable=True))
    op.add_column('pitches', sa.Column('upvotes', sa.INTEGER(), autoincrement=False, nullable=True))
    op.add_column('pitches', sa.Column('title', sa.VARCHAR(), autoincrement=False, nullable=True))
    op.add_column('pitches', sa.Column('downvotes', sa.INTEGER(), autoincrement=False, nullable=True))
    op.add_column('pitches', sa.Column('body', sa.VARCHAR(), autoincrement=False, nullable=True))
    op.add_column('pitches', sa.Column('category', sa.VARCHAR(), autoincrement=False, nullable=True))
    op.add_column('pitches', sa.Column('author', sa.VARCHAR(), autoincrement=False, nullable=True))
    op.drop_column('pitches', 'name')
    op.drop_table('comments')
    op.drop_table('lines')
    # ### end Alembic commands ###
