From 986de77b4868e48d00161c9d30071d809360e9a6 Mon Sep 17 00:00:00 2001 From: Riddhiagrawal001 <50551695+Riddhiagrawal001@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:17:59 +0530 Subject: [PATCH] fix(user_roles): migrations for backfilling user_roles entity_id (#6837) --- .../down.sql | 2 +- .../up.sql | 1 + .../down.sql | 2 ++ .../up.sql | 10 ++++++++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 migrations/2024-12-13-080558_entity-id-backfill-for-user-roles/down.sql create mode 100644 migrations/2024-12-13-080558_entity-id-backfill-for-user-roles/up.sql diff --git a/migrations/2024-12-02-110129_update-user-role-entity-type/down.sql b/migrations/2024-12-02-110129_update-user-role-entity-type/down.sql index c7c9cbeb4017..dff040ebc9e6 100644 --- a/migrations/2024-12-02-110129_update-user-role-entity-type/down.sql +++ b/migrations/2024-12-02-110129_update-user-role-entity-type/down.sql @@ -1,2 +1,2 @@ -- This file should undo anything in `up.sql` -SELECT 1; \ No newline at end of file +UPDATE user_roles SET entity_type = NULL WHERE version = 'v1'; \ No newline at end of file diff --git a/migrations/2024-12-02-110129_update-user-role-entity-type/up.sql b/migrations/2024-12-02-110129_update-user-role-entity-type/up.sql index f2759f030d50..b982a8b13730 100644 --- a/migrations/2024-12-02-110129_update-user-role-entity-type/up.sql +++ b/migrations/2024-12-02-110129_update-user-role-entity-type/up.sql @@ -1,4 +1,5 @@ -- Your SQL goes here +-- Incomplete migration, also run migrations/2024-12-13-080558_entity-id-backfill-for-user-roles UPDATE user_roles SET entity_type = CASE diff --git a/migrations/2024-12-13-080558_entity-id-backfill-for-user-roles/down.sql b/migrations/2024-12-13-080558_entity-id-backfill-for-user-roles/down.sql new file mode 100644 index 000000000000..fb372f88a12b --- /dev/null +++ b/migrations/2024-12-13-080558_entity-id-backfill-for-user-roles/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +UPDATE user_roles SET entity_id = NULL WHERE version = 'v1'; \ No newline at end of file diff --git a/migrations/2024-12-13-080558_entity-id-backfill-for-user-roles/up.sql b/migrations/2024-12-13-080558_entity-id-backfill-for-user-roles/up.sql new file mode 100644 index 000000000000..7de41d880db6 --- /dev/null +++ b/migrations/2024-12-13-080558_entity-id-backfill-for-user-roles/up.sql @@ -0,0 +1,10 @@ +-- Your SQL goes here +UPDATE user_roles +SET + entity_id = CASE + WHEN role_id = 'org_admin' THEN org_id + ELSE merchant_id + END +WHERE + version = 'v1' + AND entity_id IS NULL; \ No newline at end of file