-
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-2 adding Session deletion to store procedure
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/api-db-migrations/20230824142200__update-sp_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,52 @@ | ||
-- 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; | ||
-- Set disabled status | ||
UPDATE | ||
"Profile" | ||
SET | ||
"status" = 'disabled' | ||
WHERE | ||
"circlesAddress" = address; | ||
-- Remove CirclesAddress | ||
UPDATE | ||
"Profile" | ||
SET | ||
"circlesAddress" = NULL | ||
WHERE | ||
"circlesAddress" = address; | ||
-- Disable the Shop | ||
UPDATE | ||
"Profile" | ||
SET | ||
"shopEnabled" = FALSE | ||
WHERE | ||
id IN( | ||
SELECT | ||
"memberAtId" | ||
FROM | ||
"Membership" | ||
WHERE | ||
"memberAddress" = address | ||
AND "isAdmin" = TRUE); | ||
END | ||
$$ | ||
-- migrate:down |