-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1515 from cityofaustin/mike/19854_workgroup_reorg
Update moped_workgroup to reflect reorganization
- Loading branch information
Showing
4 changed files
with
51 additions
and
5 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
3 changes: 3 additions & 0 deletions
3
moped-database/migrations/1734717637542_update_workgroups/down.sql
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,3 @@ | ||
-- Updating moped_workgroup table will be up only. If we need to revert, we will need do it manually or | ||
-- update with a future migration. | ||
SELECT 0; |
37 changes: 37 additions & 0 deletions
37
moped-database/migrations/1734717637542_update_workgroups/up.sql
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,37 @@ | ||
-- Add soft deletes to workgroup table | ||
ALTER TABLE moped_workgroup ADD is_deleted boolean DEFAULT FALSE; | ||
COMMENT ON COLUMN moped_workgroup.is_deleted IS 'Indicates soft deletion'; | ||
|
||
INSERT INTO moped_workgroup ("workgroup_name", "workgroup_abbreviation", "department_id") VALUES | ||
('Sidewalks and Urban Trails', 'SUTD', 11); | ||
|
||
-- Soft delete existing workgroup records that are merging into the new one | ||
UPDATE moped_workgroup SET is_deleted = TRUE WHERE workgroup_name IN ('Sidewalks', 'Urban Trails'); | ||
|
||
-- Find existing users records that are associated with the workgroups that are merging | ||
-- and update them to the new workgroup row for SUTD | ||
WITH user_todos AS ( | ||
SELECT workgroup_id AS ids | ||
FROM | ||
moped_workgroup | ||
WHERE | ||
workgroup_name IN ( | ||
'Sidewalks', | ||
'Urban Trails' | ||
) | ||
), | ||
|
||
new_workgroup_row AS ( | ||
SELECT workgroup_id AS id | ||
FROM | ||
moped_workgroup | ||
WHERE | ||
workgroup_name = 'Sidewalks and Urban Trails' | ||
) | ||
|
||
UPDATE | ||
moped_users | ||
SET | ||
workgroup_id = (SELECT id FROM new_workgroup_row) | ||
WHERE | ||
workgroup_id IN (SELECT ids FROM user_todos); |
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