Skip to content

Commit ea877ec

Browse files
committed
fix extension dependencies after extension creation
1 parent 80d8539 commit ea877ec

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

migrations/db/migrations/20221207154255_create_pgsodium_and_vault.sql

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ grant pgsodium_keyiduser to postgres with admin option;
66
grant pgsodium_keyholder to postgres with admin option;
77
grant pgsodium_keymaker to postgres with admin option;
88

9-
create extension if not exists supabase_vault;
9+
do $$
10+
begin
11+
if not exists (select from pg_extension where extname = 'supabase_vault') then
12+
create extension supabase_vault;
13+
-- Creating the extension creates a table and creates a security label on the table.
14+
-- Creating the security label triggers a function that recreates these objects.
15+
-- Since the recreation happens in an extension script, these objects become owned by the `supabase_vault` extension.
16+
-- This is an issue because then we can't drop the extension without also dropping these objects.
17+
-- Thus we drop the dependency on the `supabase_vault` extension for these objects.
18+
alter extension supabase_vault drop view pgsodium.decrypted_key;
19+
alter extension supabase_vault drop function pgsodium.key_encrypt_secret;
20+
end if;
21+
end;
22+
$$;
1023

1124
-- migrate:down

0 commit comments

Comments
 (0)