-
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
6 changed files
with
97 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
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
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
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,66 @@ | ||
"""add org to timetable | ||
Revision ID: 2d2ae3b7bc65 | ||
Revises: 72095fc4eab8 | ||
Create Date: 2024-12-12 14:29:32.867950 | ||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "2d2ae3b7bc65" | ||
down_revision = "72095fc4eab8" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("local_plan_timetable", schema=None) as batch_op: | ||
batch_op.add_column(sa.Column("organisation", sa.Text(), nullable=True)) | ||
batch_op.drop_index("ix_local_plan_event_end_date") | ||
batch_op.create_index( | ||
batch_op.f("ix_local_plan_timetable_end_date"), ["end_date"], unique=False | ||
) | ||
batch_op.create_foreign_key( | ||
"fk_local_plan_timetable_organisation", | ||
"organisation", | ||
["organisation"], | ||
["organisation"], | ||
) | ||
|
||
# Find plans with exactly one organisation and update their timetable entries | ||
op.execute( | ||
""" | ||
WITH single_org_plans AS ( | ||
SELECT lpo.local_plan, MAX(lpo.organisation) AS organisation | ||
FROM local_plan_organisation lpo | ||
GROUP BY lpo.local_plan | ||
HAVING COUNT(*) = 1 | ||
) | ||
UPDATE local_plan_timetable lpt | ||
SET organisation = sop.organisation | ||
FROM single_org_plans sop | ||
WHERE lpt.local_plan_reference = sop.local_plan | ||
""" | ||
) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("local_plan_timetable", schema=None) as batch_op: | ||
batch_op.drop_constraint( | ||
"fk_local_plan_timetable_organisation", type_="foreignkey" | ||
) | ||
batch_op.drop_index(batch_op.f("ix_local_plan_timetable_end_date")) | ||
batch_op.create_index( | ||
"ix_local_plan_event_end_date", ["end_date"], unique=False | ||
) | ||
batch_op.drop_column("organisation_id") | ||
|
||
# ### end Alembic commands ### |