|
1 | 1 | -- migrate:up
|
2 | 2 |
|
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 |
14 | 3 | DO $$
|
15 | 4 | DECLARE
|
| 5 | + pgsodium_exists boolean; |
16 | 6 | vault_exists boolean;
|
17 | 7 | BEGIN
|
| 8 | + pgsodium_exists = ( |
| 9 | + select count(*) = 1 |
| 10 | + from pg_available_extensions |
| 11 | + where name = 'pgsodium' |
| 12 | + ); |
| 13 | + |
18 | 14 | vault_exists = (
|
19 | 15 | select count(*) = 1
|
20 | 16 | from pg_available_extensions
|
21 | 17 | where name = 'supabase_vault'
|
22 | 18 | );
|
23 | 19 |
|
24 |
| - IF vault_exists |
| 20 | + IF pgsodium_exists |
25 | 21 | 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; |
29 | 27 |
|
| 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; |
30 | 31 |
|
| 32 | + IF vault_exists |
| 33 | + THEN |
| 34 | + create extension if not exists supabase_vault; |
| 35 | + END IF; |
| 36 | + END IF; |
| 37 | +END $$; |
31 | 38 |
|
32 | 39 | -- migrate:down
|
0 commit comments