<filename>scan_service/alembic/versions/0001_aggregate_and_average_scan_results.py
# Copyright (c) 2014-present, Facebook, Inc.
"""aggregate and average scan results

Revision ID: 0001
Revises: 0000
Create Date: 2020-07-28 22:59:59.571169

"""
import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision = "0001"
down_revision = "0000"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "aggregated_rx_responses",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("execution_id", sa.Integer(), nullable=False),
        sa.Column("network_name", sa.String(length=255), nullable=False),
        sa.Column(
            "created_dt", sa.DateTime(), server_default=sa.text("now()"), nullable=False
        ),
        sa.Column("tx_node", sa.String(length=255), nullable=False),
        sa.Column("rx_node", sa.String(length=255), nullable=False),
        sa.Column("stats", sa.JSON(), nullable=False),
        sa.ForeignKeyConstraint(["execution_id"], ["scan_test_execution.id"]),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_aggregated_rx_responses_created_dt"),
        "aggregated_rx_responses",
        ["created_dt"],
        unique=False,
    )
    op.create_index(
        op.f("ix_aggregated_rx_responses_network_name"),
        "aggregated_rx_responses",
        ["network_name"],
        unique=False,
    )
    op.add_column(
        "connectivity_results", sa.Column("is_n_day_avg", sa.Boolean(), nullable=True)
    )
    op.add_column(
        "interference_results", sa.Column("is_n_day_avg", sa.Boolean(), nullable=True)
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column("interference_results", "is_n_day_avg")
    op.drop_column("connectivity_results", "is_n_day_avg")
    op.drop_index(
        op.f("ix_aggregated_rx_responses_network_name"),
        table_name="aggregated_rx_responses",
    )
    op.drop_index(
        op.f("ix_aggregated_rx_responses_created_dt"),
        table_name="aggregated_rx_responses",
    )
    op.drop_table("aggregated_rx_responses")
    # ### end Alembic commands ###
