-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes: #218
- Loading branch information
Showing
1 changed file
with
14 additions
and
9 deletions.
There are no files selected for viewing
23 changes: 14 additions & 9 deletions
23
database/migration/deploy/new_way_delete_esp_permission.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 |
---|---|---|
@@ -1,26 +1,31 @@ | ||
-- Deploy climat-guardian:new_way_delete_esp_permission to pg | ||
|
||
-- Function to DELETE on data and esp tables | ||
CREATE OR REMPLACE FUNCTION api.delete_esp({ id }: { id: string }) RETURN VOID AS $$ | ||
|
||
BEGIN; | ||
|
||
|
||
-- Remove permission to DELETE on data and esp tables | ||
REVOKE DELETE ON api.data TO web_user; | ||
REVOKE DELETE ON api.esp TO web_user; | ||
|
||
REVOKE DELETE ON api.data from web_user; | ||
REVOKE DELETE ON api.esp from web_user; | ||
|
||
-- Add permission to DELETE on data and esp tables | ||
GRANT DELETE ON api.data TO web_user; | ||
GRANT DELETE ON api.esp TO web_user; | ||
|
||
-- Delete the function if exists | ||
DROP FUNCTION IF EXISTS api.delete_data; | ||
|
||
-- DELETE on data and esp tables | ||
DELETE FROM api.data WHERE id = ${id} | ||
DELETE FROM api.esp WHERE id = ${id} | ||
|
||
-- Create the function | ||
CREATE OR REPLACE FUNCTION api.delete_data(id) | ||
RETURNS VOID AS $$ | ||
|
||
BEGIN | ||
-- DELETE on data and esp tables | ||
DELETE FROM api.data WHERE id = id; | ||
DELETE FROM api.esp WHERE id = id; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
|
||
$$ LANGUAGE plpgsql; | ||
END; |