"""Fix SenderPositionStatistic

Revision ID: eb571174e4b2
Revises: 0dff4f629978
Create Date: 2020-12-04 19:09:41.947668

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'eb571174e4b2'
down_revision = '0dff4f629978'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('sender_position_statistics', sa.Column('sender_id', sa.Integer(), nullable=True))
    op.create_index(op.f('ix_sender_position_statistics_sender_id'), 'sender_position_statistics', ['sender_id'], unique=False)
    op.drop_index('idx_sender_position_statistics_uc', table_name='sender_position_statistics')
    op.create_index('idx_sender_position_statistics_uc', 'sender_position_statistics', ['date', 'sender_id', 'dstcall', 'address_type', 'aircraft_type', 'stealth', 'software_version', 'hardware_version'], unique=True)
    op.create_foreign_key(None, 'sender_position_statistics', 'senders', ['sender_id'], ['id'], ondelete='CASCADE')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'sender_position_statistics', type_='foreignkey')
    op.drop_index('idx_sender_position_statistics_uc', table_name='sender_position_statistics')
    op.create_index('idx_sender_position_statistics_uc', 'sender_position_statistics', ['date', 'dstcall', 'address_type', 'aircraft_type', 'stealth', 'software_version', 'hardware_version'], unique=True)
    op.drop_index(op.f('ix_sender_position_statistics_sender_id'), table_name='sender_position_statistics')
    op.drop_column('sender_position_statistics', 'sender_id')
    # ### end Alembic commands ###
