"""Add playlist and playtimes

Revision ID: f07b96a5e60f
Revises: b0983648595e
Create Date: 2021-03-27 19:53:09.524989

"""
from alembic import op
import sqlalchemy as sa


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


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('playdates',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('lastplayed', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_playdates_lastplayed'), 'playdates', ['lastplayed'], unique=False)
    op.create_table('playlists',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(length=32), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('playlistracks',
    sa.Column('playlist_id', sa.Integer(), nullable=True),
    sa.Column('track_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['playlist_id'], ['playlists.id'], ),
    sa.ForeignKeyConstraint(['track_id'], ['tracks.id'], )
    )
    op.add_column('tracks', sa.Column('playdates_id', sa.Integer(), nullable=True))
    op.create_foreign_key(None, 'tracks', 'playdates', ['playdates_id'], ['id'])
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'tracks', type_='foreignkey')
    op.drop_column('tracks', 'playdates_id')
    op.drop_table('playlistracks')
    op.drop_table('playlists')
    op.drop_index(op.f('ix_playdates_lastplayed'), table_name='playdates')
    op.drop_table('playdates')
    # ### end Alembic commands ###
