Skip to content

Commit

Permalink
missing migration file
Browse files Browse the repository at this point in the history
  • Loading branch information
ashimali committed May 15, 2024
1 parent 0aa5d38 commit ad80adb
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions migrations/versions/376575e0c068_add_local_land_charges_boolean.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""add local land charges boolean
Revision ID: 376575e0c068
Revises: 7d785f99a5fb
Create Date: 2024-05-15 15:59:40.160245
"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "376575e0c068"
down_revision = "7d785f99a5fb"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("consideration", schema=None) as batch_op:
batch_op.add_column(
sa.Column("is_local_land_charge", sa.Boolean(), nullable=True)
)

known_local_land_charges = [
"conservation-areas",
"enforcement-notices",
"tree-preservation-orders",
"assets-of-community-value",
"compulsory-purchase-orders",
"opencast-coal-prospecting-areas",
"listed-buildings",
]

op.execute("UPDATE consideration SET is_local_land_charge = false")

for local_land_charge in known_local_land_charges:
op.execute(
f"UPDATE consideration SET is_local_land_charge = true WHERE slug = '{local_land_charge}'"
)

with op.batch_alter_table("consideration", schema=None) as batch_op:
batch_op.alter_column("is_local_land_charge", nullable=False)

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("consideration", schema=None) as batch_op:
batch_op.drop_column("is_local_land_charge")

# ### end Alembic commands ###

0 comments on commit ad80adb

Please sign in to comment.