Skip to content

Commit d455bbf

Browse files
committed
chore: safeguard both pgsodium and vault
1 parent 3023562 commit d455bbf

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed
Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
11
-- migrate:up
22

3-
create extension if not exists pgsodium;
4-
5-
grant pgsodium_keyiduser to postgres with admin option;
6-
grant pgsodium_keyholder to postgres with admin option;
7-
grant pgsodium_keymaker to postgres with admin option;
8-
9-
grant execute on function pgsodium.crypto_aead_det_decrypt(bytea, bytea, uuid, bytea) to service_role;
10-
grant execute on function pgsodium.crypto_aead_det_encrypt(bytea, bytea, uuid, bytea) to service_role;
11-
grant execute on function pgsodium.crypto_aead_det_keygen to service_role;
12-
13-
-- Only install as well if the extension is actually installed
143
DO $$
154
DECLARE
5+
pgsodium_exists boolean;
166
vault_exists boolean;
177
BEGIN
8+
pgsodium_exists = (
9+
select count(*) = 1
10+
from pg_available_extensions
11+
where name = 'pgsodium'
12+
);
13+
1814
vault_exists = (
1915
select count(*) = 1
2016
from pg_available_extensions
2117
where name = 'supabase_vault'
2218
);
2319

24-
IF vault_exists
20+
IF pgsodium_exists
2521
THEN
26-
create extension if not exists supabase_vault;
27-
END IF;
28-
END $$;
22+
create extension if not exists pgsodium;
23+
24+
grant pgsodium_keyiduser to postgres with admin option;
25+
grant pgsodium_keyholder to postgres with admin option;
26+
grant pgsodium_keymaker to postgres with admin option;
2927

28+
grant execute on function pgsodium.crypto_aead_det_decrypt(bytea, bytea, uuid, bytea) to service_role;
29+
grant execute on function pgsodium.crypto_aead_det_encrypt(bytea, bytea, uuid, bytea) to service_role;
30+
grant execute on function pgsodium.crypto_aead_det_keygen to service_role;
3031

32+
IF vault_exists
33+
THEN
34+
create extension if not exists supabase_vault;
35+
END IF;
36+
END IF;
37+
END $$;
3138

3239
-- migrate:down

0 commit comments

Comments
 (0)