diff --git a/moped-database/migrations/1736442550315_update_entities/up.sql b/moped-database/migrations/1736442550315_update_entities/up.sql index 5704f87a26..173542c8e2 100644 --- a/moped-database/migrations/1736442550315_update_entities/up.sql +++ b/moped-database/migrations/1736442550315_update_entities/up.sql @@ -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 ( @@ -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 diff --git a/moped-database/recipes/update_merged_funding_sources.sql b/moped-database/recipes/update_merged_funding_sources.sql new file mode 100644 index 0000000000..ac8324e2d4 --- /dev/null +++ b/moped-database/recipes/update_merged_funding_sources.sql @@ -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);