"""Initialize.

Revision ID: layout
Revises:
Create Date: 2018-02-22 10:37:26.587235+00:00

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

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


def upgrade():  # noqa D103  TODO
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('track',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('length', sa.Integer(), nullable=True),
                    sa.Column('origin', postgresql.ENUM('youtube', 'soundcloud', name='origin'), nullable=True),
                    sa.Column('extid', sa.Text(), nullable=True),
                    sa.Column('name', sa.Text(), nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    sa.UniqueConstraint('origin', 'extid')
                    )
    op.create_table('user',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('dtid', sa.Text(), nullable=True),
                    sa.Column('username', sa.Text(), nullable=True),
                    sa.Column('country', sa.Text(), nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    sa.UniqueConstraint('dtid')
                    )
    op.create_table('playback',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('track_id', sa.Integer(), nullable=True),
                    sa.Column('user_id', sa.Integer(), nullable=True),
                    sa.Column('start', sa.DateTime(), nullable=True),
                    sa.ForeignKeyConstraint(['track_id'], ['track.id'], ),
                    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
                    sa.PrimaryKeyConstraint('id'),
                    sa.UniqueConstraint('start')
                    )
    op.create_table('user_action',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('ts', sa.DateTime(), nullable=True),
                    sa.Column('playback_id', sa.Integer(), nullable=True),
                    sa.Column('user_id', sa.Integer(), nullable=True),
                    sa.Column('action', postgresql.ENUM('skip', 'upvote', 'downvote', name='action'), nullable=True),
                    sa.ForeignKeyConstraint(['playback_id'], ['playback.id'], ),
                    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
                    sa.PrimaryKeyConstraint('id')
                    )
    # ### end Alembic commands ###


def downgrade():  # noqa D103  TODO
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('user_action')
    op.drop_table('playback')
    op.drop_table('user')
    op.drop_table('track')
    op.execute('DROP TYPE origin')
    op.execute('DROP TYPE action')
    # ### end Alembic commands ###
