"""add_location_columns_to_weather_sensor_table

Revision ID: 9c7fc8e46f1e
Revises: 2c9a32614784
Create Date: 2018-07-27 12:38:27.006000

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "9c7fc8e46f1e"
down_revision = "2c9a32614784"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    # We need to add the nullable constraint after we set default values for any existing sensors.
    # These only matter for our current development, not when you set up a new database!
    # This default location is Jeju island.
    op.add_column("weather_sensor", sa.Column("latitude", sa.Float()))
    op.execute("UPDATE weather_sensor SET latitude = 33.4843866")
    op.alter_column("weather_sensor", "latitude", nullable=False)
    op.add_column("weather_sensor", sa.Column("longitude", sa.Float()))
    op.execute("UPDATE weather_sensor SET longitude = 126.477859")
    op.alter_column("weather_sensor", "longitude", nullable=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column("weather_sensor", "latitude")
    op.drop_column("weather_sensor", "longitude")
    # ### end Alembic commands ###
