Skip to content

Commit

Permalink
fix: fixing the function
Browse files Browse the repository at this point in the history
Closes: #218
  • Loading branch information
ColinRgm committed Jan 9, 2025
1 parent b8b0cbe commit de6dfd0
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions database/migration/deploy/new_way_delete_esp_permission.sql
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;

0 comments on commit de6dfd0

Please sign in to comment.