Skip to content

Commit

Permalink
Fix aliases to be more readable; add missing sql recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
mddilley committed Jan 9, 2025
1 parent 4141ab8 commit f9dd75b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
18 changes: 9 additions & 9 deletions moped-database/migrations/1736442550315_update_entities/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ INSERT INTO
moped_entity (entity_name, department_id, workgroup_id, organization_id)
SELECT
'COA TPW Sidewalks and Urban Trails' AS entity_name,
d.department_id,
w.workgroup_id,
o.organization_id
department.department_id,
workgroup.workgroup_id,
organization.organization_id
FROM
department AS d,
workgroup AS w,
organization AS o;
department,
workgroup,
organization;

-- Insert new row for COA TPW with appropriate department_id and organization_id (no associated workgroup)
WITH organization AS (
Expand All @@ -65,11 +65,11 @@ department AS (
INSERT INTO moped_entity (entity_name, department_id, workgroup_id, organization_id, is_deleted)
SELECT
'COA TPW' AS entity_name,
d.department_id,
department.department_id,
NULL AS workgroup_id,
o.organization_id,
organization.organization_id,
FALSE AS is_deleted
FROM department AS d, organization AS o;
FROM department, organization;

-- Find any records (except the soft-deleted above) that have either ATD or PWD in them and replace with TPW
UPDATE moped_entity
Expand Down
28 changes: 28 additions & 0 deletions moped-database/recipes/update_merged_funding_sources.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- This example finds existing project funding sources that are associated with the sources that merged
-- and updates them to the new funding source.
-- See https://github.com/cityofaustin/atd-moped/pull/1486
WITH funding_source_todos AS (
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);

0 comments on commit f9dd75b

Please sign in to comment.