Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update project fund sources to reflect reorganization #1486

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Updating funding sources will be up only. If we need to revert, we will need do it manually or
-- update with a future migration.
SELECT 0;
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-- Insert new funding source and soft-delete existing funding sources that are merging into the new one
INSERT INTO "public"."moped_fund_sources" ("funding_source_name") VALUES
('Austin Transportation and Public Works');

UPDATE moped_fund_sources SET is_deleted = true WHERE funding_source_name IN ('Austin Transportation', 'Public Works');

-- Find existing project funding records that are associated with the funding sources that are merging
-- and update them to the new funding source called Austin Transportation and Public Works
WITH funding_source_todos AS (
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely convinced these CTEs make this more readable since there are still sub-queries in the UPDATE statement below. Open to updating if anyone feels strongly about it!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like them! i wish i could bookmark this migration for the next time we need to do this kind of operation.

i suppose i can bookmark it... 🤔

SELECT funding_source_id AS ids
FROM
moped_fund_sources
WHERE
funding_source_name IN (
'Austin Transportation',
'Public Works'
)
),

new_funding_source_row AS (
SELECT funding_source_id AS id
FROM
moped_fund_sources
WHERE
funding_source_name = 'Austin Transportation and Public Works'
)

UPDATE
moped_proj_funding
SET
funding_source_id = (SELECT id FROM new_funding_source_row)
WHERE
funding_source_id IN (SELECT ids FROM funding_source_todos);