forked from ytgov/travel-authorization
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #170 from icefoganalytics/issue-166/departmental-a…
…dministration-create-a-travel-auth-for-another-employee-within-my-department Part 1: Departmental Administration: Create a Travel Auth for Another Employee Within My Department
- Loading branch information
Showing
24 changed files
with
501 additions
and
56 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
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
72 changes: 72 additions & 0 deletions
72
api/src/db/migrations/20240122154624_make-user-role-names-more-readable.ts
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,72 @@ | ||
import { Knex } from "knex"; | ||
|
||
|
||
export async function up(knex: Knex): Promise<void> { | ||
await knex.raw(` | ||
WITH unnested_roles AS ( | ||
SELECT | ||
id | ||
, CASE WHEN "role" = 'dept_admin' THEN 'department_admin' | ||
ELSE "role" | ||
END AS transformed_role | ||
FROM | ||
"users" | ||
, unnest(roles) AS "role" | ||
WHERE | ||
roles IS NOT NULL | ||
) | ||
, aggregated_updated_roles AS ( | ||
SELECT | ||
id | ||
, array_agg(transformed_role) AS roles | ||
FROM | ||
unnested_roles | ||
GROUP BY | ||
id | ||
) | ||
UPDATE | ||
"users" | ||
SET | ||
roles = aggregated_updated_roles.roles | ||
FROM | ||
aggregated_updated_roles | ||
WHERE | ||
"users".id = aggregated_updated_roles.id | ||
AND "users".roles IS NOT NULL; | ||
`) | ||
} | ||
|
||
|
||
export async function down(knex: Knex): Promise<void> { | ||
await knex.raw(` | ||
WITH unnested_roles AS ( | ||
SELECT | ||
id | ||
, CASE WHEN "role" = 'department_admin' THEN 'dept_admin' | ||
ELSE "role" | ||
END AS transformed_role | ||
FROM | ||
"users" | ||
, unnest(roles) AS "role" | ||
WHERE | ||
roles IS NOT NULL | ||
) | ||
, aggregated_updated_roles AS ( | ||
SELECT | ||
id | ||
, array_agg(transformed_role) AS roles | ||
FROM | ||
unnested_roles | ||
GROUP BY | ||
id) | ||
UPDATE | ||
"users" | ||
SET | ||
roles = aggregated_updated_roles.roles | ||
FROM | ||
aggregated_updated_roles | ||
WHERE | ||
"users".id = aggregated_updated_roles.id | ||
AND "users".roles IS NOT NULL; | ||
`) | ||
} |
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
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
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
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
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
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
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
Oops, something went wrong.