@@ -78,14 +78,6 @@ CREATE SCHEMA realtime;
78
78
79
79
CREATE SCHEMA storage ;
80
80
81
-
82
- --
83
- -- Name: vault; Type: SCHEMA; Schema: -; Owner: -
84
- --
85
-
86
- CREATE SCHEMA vault ;
87
-
88
-
89
81
--
90
82
-- Name: pg_graphql; Type: EXTENSION; Schema: -; Owner: -
91
83
--
@@ -141,19 +133,43 @@ CREATE EXTENSION IF NOT EXISTS pgjwt WITH SCHEMA extensions;
141
133
142
134
COMMENT ON EXTENSION pgjwt IS ' JSON Web Token API for Postgresql' ;
143
135
144
-
145
136
--
146
- -- Name: supabase_vault; Type: EXTENSION; Schema: -; Owner: -
147
137
--
138
+ --
139
+
140
+ DO $$
141
+ DECLARE
142
+ vault_exists boolean ;
143
+ BEGIN
144
+ vault_exists = (
145
+ select count (* ) = 1
146
+ from pg_available_extensions
147
+ where name = ' supabase_vault'
148
+ );
148
149
149
- CREATE EXTENSION IF NOT EXISTS supabase_vault WITH SCHEMA vault;
150
+ IF vault_exists
151
+ THEN
152
+
153
+ --
154
+ -- Name: vault; Type: SCHEMA; Schema: -; Owner: -
155
+ --
150
156
157
+ CREATE SCHEMA vault ;
158
+ --
159
+ -- Name: supabase_vault; Type: EXTENSION; Schema: -; Owner: -
160
+ --
151
161
152
- --
153
- -- Name: EXTENSION supabase_vault; Type: COMMENT; Schema: -; Owner: -
154
- --
162
+ CREATE EXTENSION IF NOT EXISTS supabase_vault WITH SCHEMA vault;
163
+
164
+
165
+ --
166
+ -- Name: EXTENSION supabase_vault; Type: COMMENT; Schema: -; Owner: -
167
+ --
168
+
169
+ COMMENT ON EXTENSION supabase_vault IS ' Supabase Vault Extension' ;
155
170
156
- COMMENT ON EXTENSION supabase_vault IS ' Supabase Vault Extension' ;
171
+ END IF;
172
+ END $$;
157
173
158
174
159
175
--
@@ -577,23 +593,38 @@ $$;
577
593
-- Name: secrets_encrypt_secret_secret(); Type: FUNCTION; Schema: vault; Owner: -
578
594
--
579
595
580
- CREATE FUNCTION vault .secrets_encrypt_secret_secret() RETURNS trigger
581
- LANGUAGE plpgsql
582
- AS $$
583
- BEGIN
584
- new .secret = CASE WHEN new .secret IS NULL THEN NULL ELSE
585
- CASE WHEN new .key_id IS NULL THEN NULL ELSE pg_catalog .encode (
586
- pgsodium .crypto_aead_det_encrypt (
587
- pg_catalog .convert_to (new .secret , ' utf8' ),
588
- pg_catalog .convert_to ((new .id ::text || new .description ::text || new .created_at ::text || new .updated_at ::text )::text , ' utf8' ),
589
- new .key_id ::uuid,
590
- new .nonce
591
- ),
592
- ' base64' ) END END;
593
- RETURN new;
594
- END;
595
- $$;
596
+ DO $$
597
+ DECLARE
598
+ vault_exists boolean ;
599
+ BEGIN
600
+ vault_exists = (
601
+ select count (* ) = 1
602
+ from pg_available_extensions
603
+ where name = ' supabase_vault'
604
+ );
605
+
606
+ IF vault_exists
607
+ THEN
608
+
609
+ CREATE FUNCTION vault .secrets_encrypt_secret_secret() RETURNS trigger
610
+ LANGUAGE plpgsql
611
+ AS $$
612
+ BEGIN
613
+ new .secret = CASE WHEN new .secret IS NULL THEN NULL ELSE
614
+ CASE WHEN new .key_id IS NULL THEN NULL ELSE pg_catalog .encode (
615
+ pgsodium .crypto_aead_det_encrypt (
616
+ pg_catalog .convert_to (new .secret , ' utf8' ),
617
+ pg_catalog .convert_to ((new .id ::text || new .description ::text || new .created_at ::text || new .updated_at ::text )::text , ' utf8' ),
618
+ new .key_id ::uuid,
619
+ new .nonce
620
+ ),
621
+ ' base64' ) END END;
622
+ RETURN new;
623
+ END;
624
+ $$;
596
625
626
+ END IF;
627
+ END $$;
597
628
598
629
SET default_tablespace = ' ' ;
599
630
@@ -785,25 +816,40 @@ CREATE TABLE storage.objects (
785
816
-- Name: decrypted_secrets; Type: VIEW; Schema: vault; Owner: -
786
817
--
787
818
788
- CREATE VIEW vault .decrypted_secrets AS
789
- SELECT secrets .id ,
790
- secrets .name ,
791
- secrets .description ,
792
- secrets .secret ,
793
- CASE
794
- WHEN (secrets .secret IS NULL ) THEN NULL ::text
795
- ELSE
819
+ DO $$
820
+ DECLARE
821
+ vault_exists boolean ;
822
+ BEGIN
823
+ vault_exists = (
824
+ select count (* ) = 1
825
+ from pg_available_extensions
826
+ where name = ' supabase_vault'
827
+ );
828
+
829
+ IF vault_exists
830
+ THEN
831
+
832
+ CREATE VIEW vault .decrypted_secrets AS
833
+ SELECT secrets .id ,
834
+ secrets .name ,
835
+ secrets .description ,
836
+ secrets .secret ,
796
837
CASE
797
- WHEN (secrets .key_id IS NULL ) THEN NULL ::text
798
- ELSE convert_from(pgsodium .crypto_aead_det_decrypt (decode(secrets .secret , ' base64' ::text ), convert_to(((((secrets .id )::text || secrets .description ) || (secrets .created_at )::text ) || (secrets .updated_at )::text ), ' utf8' ::name), secrets .key_id , secrets .nonce ), ' utf8' ::name)
799
- END
800
- END AS decrypted_secret,
801
- secrets .key_id ,
802
- secrets .nonce ,
803
- secrets .created_at ,
804
- secrets .updated_at
805
- FROM vault .secrets ;
838
+ WHEN (secrets .secret IS NULL ) THEN NULL ::text
839
+ ELSE
840
+ CASE
841
+ WHEN (secrets .key_id IS NULL ) THEN NULL ::text
842
+ ELSE convert_from(pgsodium .crypto_aead_det_decrypt (decode(secrets .secret , ' base64' ::text ), convert_to(((((secrets .id )::text || secrets .description ) || (secrets .created_at )::text ) || (secrets .updated_at )::text ), ' utf8' ::name), secrets .key_id , secrets .nonce ), ' utf8' ::name)
843
+ END
844
+ END AS decrypted_secret,
845
+ secrets .key_id ,
846
+ secrets .nonce ,
847
+ secrets .created_at ,
848
+ secrets .updated_at
849
+ FROM vault .secrets ;
806
850
851
+ END IF;
852
+ END $$;
807
853
808
854
--
809
855
-- Name: refresh_tokens id; Type: DEFAULT; Schema: auth; Owner: -
0 commit comments