-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
migrations/versions/376575e0c068_add_local_land_charges_boolean.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ### |