"""Add ReceiverRanking

Revision ID: 7f5b8f65a977
Revises: c53fdb39f5a5
Create Date: 2020-12-02 22:33:58.821112

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '7f5b8f65a977'
down_revision = 'c53fdb39f5a5'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('receiver_rankings',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('date', sa.Date(), nullable=True),
        sa.Column('local_rank', sa.Integer(), nullable=True),
        sa.Column('global_rank', sa.Integer(), nullable=True),
        sa.Column('max_distance', sa.Float(precision=2), nullable=True),
        sa.Column('max_normalized_quality', sa.Float(precision=2), nullable=True),
        sa.Column('messages_count', sa.Integer(), nullable=True),
        sa.Column('coverages_count', sa.Integer(), nullable=True),
        sa.Column('senders_count', sa.Integer(), nullable=True),
        sa.Column('receiver_id', sa.Integer(), nullable=True),
        sa.Column('country_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['country_id'], ['countries.gid'], ondelete='CASCADE'),
        sa.ForeignKeyConstraint(['receiver_id'], ['receivers.id'], ondelete='CASCADE'),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index('idx_receiver_rankings_uc', 'receiver_rankings', ['date', 'receiver_id'], unique=True)
    op.create_index(op.f('ix_receiver_rankings_country_id'), 'receiver_rankings', ['country_id'], unique=False)
    op.create_index(op.f('ix_receiver_rankings_receiver_id'), 'receiver_rankings', ['receiver_id'], unique=False)

    op.drop_column('receiver_statuses', 'agl')
    op.drop_column('receiver_statuses', 'location_mgrs')
    op.drop_column('receiver_statuses', 'location_mgrs_short')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('receiver_statuses', sa.Column('location_mgrs_short', sa.VARCHAR(length=9), autoincrement=False, nullable=True))
    op.add_column('receiver_statuses', sa.Column('location_mgrs', sa.VARCHAR(length=15), autoincrement=False, nullable=True))
    op.add_column('receiver_statuses', sa.Column('agl', sa.REAL(), autoincrement=False, nullable=True))

    op.drop_index(op.f('ix_receiver_rankings_receiver_id'), table_name='receiver_rankings')
    op.drop_index(op.f('ix_receiver_rankings_country_id'), table_name='receiver_rankings')
    op.drop_index('idx_receiver_rankings_uc', table_name='receiver_rankings')
    op.drop_table('receiver_rankings')
    # ### end Alembic commands ###
