Skip to content

Commit

Permalink
Merge pull request #1515 from cityofaustin/mike/19854_workgroup_reorg
Browse files Browse the repository at this point in the history
Update moped_workgroup to reflect reorganization
  • Loading branch information
mddilley authored Jan 2, 2025
2 parents 6cdc5d6 + c48cafa commit 0ca7460
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
11 changes: 7 additions & 4 deletions moped-database/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5469,25 +5469,28 @@
- role: moped-admin
permission:
columns:
- date_added
- is_deleted
- workgroup_id
- workgroup_name
- date_added
filter: {}
allow_aggregations: true
- role: moped-editor
permission:
columns:
- date_added
- is_deleted
- workgroup_id
- workgroup_name
- date_added
filter: {}
allow_aggregations: true
- role: moped-viewer
permission:
columns:
- workgroup_name
- workgroup_id
- date_added
- is_deleted
- workgroup_id
- workgroup_name
filter: {}
allow_aggregations: true
- table:
Expand Down
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 moped-database/migrations/1734717637542_update_workgroups/up.sql
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);
5 changes: 4 additions & 1 deletion moped-editor/src/queries/workgroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { gql } from "@apollo/client";

export const WORKGROUPS_QUERY = gql`
query GetWorkgroups {
moped_workgroup(order_by: {workgroup_name: asc}) {
moped_workgroup(
order_by: { workgroup_name: asc }
where: { is_deleted: { _eq: false } }
) {
workgroup_id
workgroup_name
}
Expand Down

0 comments on commit 0ca7460

Please sign in to comment.