-
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.
Browse files
Browse the repository at this point in the history
…ty-for-db-admin-to-disable-an-account-FINAL fixing stored procedure to disable users
- Loading branch information
Showing
2 changed files
with
116 additions
and
1 deletion.
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
115 changes: 115 additions & 0 deletions
115
src/api-db-migrations/20230907111300__fix_DisableProfileAndShopProc.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,115 @@ | ||
-- migrate:up | ||
CREATE OR REPLACE PROCEDURE sp_DisableProfileAndShop(address varchar(100)) | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
-- Remove Session | ||
DELETE FROM "Session" | ||
WHERE "Session"."profileId" IN( | ||
SELECT | ||
"id" | ||
FROM | ||
"Profile" | ||
WHERE | ||
"circlesAddress" = address); | ||
-- Copy circlesAddress to disabledCirclesAddress | ||
UPDATE | ||
"Profile" | ||
SET | ||
"disabledCirclesAddress" = "circlesAddress" | ||
WHERE | ||
"circlesAddress" = address; | ||
-- Copy circlesSafeOwner to disabledCirclesSafeOwner | ||
UPDATE | ||
"Profile" | ||
SET | ||
"disabledCirclesSafeOwner" = "circlesSafeOwner" | ||
WHERE | ||
"circlesAddress" = address; | ||
-- Set disabled status | ||
UPDATE | ||
"Profile" | ||
SET | ||
"status" = 'disabled' | ||
WHERE | ||
"circlesAddress" = address; | ||
-- Disable the Shop for the Person Entry | ||
UPDATE | ||
"Profile" | ||
SET | ||
"shopEnabled" = FALSE | ||
WHERE | ||
"circlesAddress" = address; | ||
-- Remove circlesSafeOwner | ||
UPDATE | ||
"Profile" | ||
SET | ||
"circlesSafeOwner" = NULL | ||
WHERE | ||
"circlesAddress" = address; | ||
-- Remove CirclesAddress | ||
UPDATE | ||
"Profile" | ||
SET | ||
"circlesAddress" = NULL | ||
WHERE | ||
"circlesAddress" = address; | ||
-- Disable the Shop for the Orga Entry | ||
UPDATE | ||
"Profile" | ||
SET | ||
"shopEnabled" = FALSE | ||
WHERE | ||
id IN( | ||
SELECT | ||
"createdByProfileId" | ||
FROM | ||
"Membership" | ||
WHERE | ||
"memberAddress" = address | ||
AND "isAdmin" = TRUE); | ||
-- copy circlesAddress for the Orga Entry | ||
UPDATE | ||
"Profile" | ||
SET | ||
"disabledCirclesAddress" = "circlesAddress" | ||
WHERE | ||
id IN( | ||
SELECT | ||
"memberAtId" | ||
FROM | ||
"Membership" | ||
WHERE | ||
"memberAddress" = address | ||
AND "isAdmin" = TRUE); | ||
-- Remove circlesAddress for Orga Entry | ||
UPDATE | ||
"Profile" | ||
SET | ||
"circlesAddress" = NULL | ||
WHERE | ||
id IN( | ||
SELECT | ||
"memberAtId" | ||
FROM | ||
"Membership" | ||
WHERE | ||
"memberAddress" = address | ||
AND "isAdmin" = TRUE); | ||
-- set status for Orga Entry to disabled | ||
UPDATE | ||
"Profile" | ||
SET | ||
"status" = 'disabled' | ||
WHERE | ||
id IN( | ||
SELECT | ||
"memberAtId" | ||
FROM | ||
"Membership" | ||
WHERE | ||
"memberAddress" = address | ||
AND "isAdmin" = TRUE); | ||
END | ||
$$ | ||
-- migrate:down |