supabase-operator/assets/migrations/migrations/20221207154255_create_pgsodium_and_vault.sql
Peter Kurfer 12090c913a
Some checks failed
E2E Tests / Run on Ubuntu (push) Failing after 20s
Lint / Run on Ubuntu (push) Failing after 3m45s
Tests / Run on Ubuntu (push) Failing after 16m8s
feat(db): prepare migrations and core CRD
2024-12-13 09:09:14 +01:00

40 lines
1 KiB
SQL

-- migrate:up
DO $$
DECLARE
pgsodium_exists boolean;
vault_exists boolean;
BEGIN
pgsodium_exists = (
select count(*) = 1
from pg_available_extensions
where name = 'pgsodium'
and default_version in ('3.1.6', '3.1.7', '3.1.8', '3.1.9')
);
vault_exists = (
select count(*) = 1
from pg_available_extensions
where name = 'supabase_vault'
);
IF pgsodium_exists
THEN
create extension if not exists pgsodium;
grant pgsodium_keyiduser to postgres with admin option;
grant pgsodium_keyholder to postgres with admin option;
grant pgsodium_keymaker to postgres with admin option;
grant execute on function pgsodium.crypto_aead_det_decrypt(bytea, bytea, uuid, bytea) to service_role;
grant execute on function pgsodium.crypto_aead_det_encrypt(bytea, bytea, uuid, bytea) to service_role;
grant execute on function pgsodium.crypto_aead_det_keygen to service_role;
IF vault_exists
THEN
create extension if not exists supabase_vault;
END IF;
END IF;
END $$;
-- migrate:down