Repository navigation
refactor: add schema snapshot #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #! /usr/bin/env bash | ||
| xpg psql \ | ||
| --file=<(cat << 'EOF' | ||
| DO $$ | ||
| DECLARE | ||
| extension_objects text[]; | ||
| extension_object text; | ||
| BEGIN | ||
|
|
||
| SELECT array_agg(pg_catalog.pg_describe_object(classid, objid, 0)) into extension_objects | ||
| FROM pg_catalog.pg_depend | ||
| INNER JOIN ( | ||
| SELECT e.oid | ||
| FROM pg_catalog.pg_extension e | ||
| WHERE e.extname OPERATOR(pg_catalog.=) 'supabase_vault' | ||
| COLLATE pg_catalog.default | ||
| ORDER BY 1 | ||
| ) AS extension_oid | ||
| ON extension_oid.oid = refobjid | ||
| WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass | ||
| AND deptype = 'e' | ||
| ORDER BY 1; | ||
|
|
||
| FOR extension_object IN select unnest(extension_objects) LOOP | ||
| BEGIN | ||
| EXECUTE 'alter extension supabase_vault drop ' || extension_object; | ||
| EXCEPTION WHEN OTHERS THEN | ||
| RAISE NOTICE 'failed on %: %', extension_object, sqlerrm; | ||
| END; | ||
| END LOOP; | ||
|
|
||
| END; | ||
| $$; | ||
| EOF) \ | ||
| --command="\\! pg_dump --restrict-key=0 --schema=vault --user=postgres --schema-only | grep -v '^\\\\restrict 0$' | grep -v '^\\\\unrestrict 0$' | grep -v '^SET .*;' | grep -v 'SELECT pg_catalog.set_config' | pgpp > supabase_vault.sql" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,7 @@ pkgs.mkShell { | |
| }; | ||
| }) | ||
| pkgs.libsodium | ||
| pkgs.python313Packages.pglast | ||
| style | ||
| styleCheck | ||
| ]; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| CREATE SCHEMA vault; | ||
|
|
||
| ALTER SCHEMA vault OWNER TO postgres; | ||
|
|
||
| CREATE FUNCTION vault._crypto_aead_det_decrypt(message bytea | ||
| , additional bytea | ||
| , key_id bigint | ||
| , context bytea = CAST('\x7067736f6469756d' AS bytea) | ||
| , nonce bytea = CAST(NULL AS bytea)) | ||
| RETURNS bytea | ||
| LANGUAGE c IMMUTABLE AS '$libdir/supabase_vault' | ||
| , 'pgsodium_crypto_aead_det_decrypt_by_id'; | ||
|
|
||
| ALTER FUNCTION vault._crypto_aead_det_decrypt (message bytea, additional bytea, key_id bigint, context bytea, nonce bytea) OWNER TO postgres; | ||
|
|
||
| CREATE FUNCTION vault._crypto_aead_det_encrypt(message bytea | ||
| , additional bytea | ||
| , key_id bigint | ||
| , context bytea = CAST('\x7067736f6469756d' AS bytea) | ||
| , nonce bytea = CAST(NULL AS bytea)) | ||
| RETURNS bytea | ||
| LANGUAGE c IMMUTABLE AS '$libdir/supabase_vault' | ||
| , 'pgsodium_crypto_aead_det_encrypt_by_id'; | ||
|
|
||
| ALTER FUNCTION vault._crypto_aead_det_encrypt (message bytea, additional bytea, key_id bigint, context bytea, nonce bytea) OWNER TO postgres; | ||
|
|
||
| CREATE FUNCTION vault._crypto_aead_det_noncegen() | ||
| RETURNS bytea | ||
| LANGUAGE c IMMUTABLE AS '$libdir/supabase_vault' | ||
| , 'pgsodium_crypto_aead_det_noncegen'; | ||
|
|
||
| ALTER FUNCTION vault._crypto_aead_det_noncegen () OWNER TO postgres; | ||
|
|
||
| CREATE FUNCTION vault.create_secret(new_secret text | ||
| , new_name text = CAST(NULL AS text) | ||
| , new_description text = CAST('' AS text) | ||
| , new_key_id uuid = CAST(NULL AS uuid)) | ||
| RETURNS uuid | ||
| LANGUAGE plpgsql SECURITY DEFINER SET search_path TO 'pg_catalog', 'pg_temp' | ||
| AS $$ | ||
| DECLARE | ||
| rec record; | ||
| BEGIN | ||
| INSERT INTO vault.secrets (secret, name, description) | ||
| VALUES ( | ||
| new_secret, | ||
| new_name, | ||
| new_description | ||
| ) | ||
| RETURNING * INTO rec; | ||
| UPDATE vault.secrets s | ||
| SET secret = encode(vault._crypto_aead_det_encrypt( | ||
| message := convert_to(rec.secret, 'utf8'), | ||
| additional := convert_to(s.id::text, 'utf8'), | ||
| key_id := 0, | ||
| context := 'pgsodium'::bytea, | ||
| nonce := rec.nonce | ||
| ), 'base64') | ||
| WHERE id = rec.id; | ||
| RETURN rec.id; | ||
| END | ||
| $$; | ||
|
|
||
| ALTER FUNCTION vault.create_secret (new_secret text, new_name text, new_description text, new_key_id uuid) OWNER TO postgres; | ||
|
|
||
| CREATE FUNCTION vault.update_secret(secret_id uuid | ||
| , new_secret text = CAST(NULL AS text) | ||
| , new_name text = CAST(NULL AS text) | ||
| , new_description text = CAST(NULL AS text) | ||
| , new_key_id uuid = CAST(NULL AS uuid)) | ||
| RETURNS void | ||
| LANGUAGE plpgsql SECURITY DEFINER SET search_path TO 'pg_catalog', 'pg_temp' | ||
| AS $$ | ||
| DECLARE | ||
| decrypted_secret text := (SELECT decrypted_secret FROM vault.decrypted_secrets WHERE id = secret_id); | ||
| BEGIN | ||
| UPDATE vault.secrets s | ||
| SET | ||
| secret = CASE WHEN new_secret IS NULL THEN s.secret | ||
| ELSE encode(vault._crypto_aead_det_encrypt( | ||
| message := convert_to(new_secret, 'utf8'), | ||
| additional := convert_to(s.id::text, 'utf8'), | ||
| key_id := 0, | ||
| context := 'pgsodium'::bytea, | ||
| nonce := s.nonce | ||
| ), 'base64') END, | ||
| name = coalesce(new_name, s.name), | ||
| description = coalesce(new_description, s.description), | ||
| updated_at = now() | ||
| WHERE s.id = secret_id; | ||
| END | ||
| $$; | ||
|
|
||
| ALTER FUNCTION vault.update_secret (secret_id uuid, new_secret text, new_name text, new_description text, new_key_id uuid) OWNER TO postgres; | ||
|
|
||
| GRANT USAGE | ||
| ON SCHEMA vault | ||
| TO bob | ||
| WITH GRANT OPTION; | ||
|
|
||
| REVOKE ALL PRIVILEGES | ||
| ON FUNCTION vault._crypto_aead_det_decrypt (message bytea, additional bytea, key_id bigint, context bytea, nonce bytea) | ||
| FROM PUBLIC; | ||
|
|
||
| GRANT ALL PRIVILEGES | ||
| ON FUNCTION vault._crypto_aead_det_decrypt (message bytea, additional bytea, key_id bigint, context bytea, nonce bytea) | ||
| TO bob | ||
| WITH GRANT OPTION; | ||
|
|
||
| REVOKE ALL PRIVILEGES | ||
| ON FUNCTION vault._crypto_aead_det_encrypt (message bytea, additional bytea, key_id bigint, context bytea, nonce bytea) | ||
| FROM PUBLIC; | ||
|
|
||
| REVOKE ALL PRIVILEGES | ||
| ON FUNCTION vault._crypto_aead_det_noncegen () | ||
| FROM PUBLIC; | ||
|
|
||
| REVOKE ALL PRIVILEGES | ||
| ON FUNCTION vault.create_secret (new_secret text, new_name text, new_description text, new_key_id uuid) | ||
| FROM PUBLIC; | ||
|
|
||
| GRANT ALL PRIVILEGES | ||
| ON FUNCTION vault.create_secret (new_secret text, new_name text, new_description text, new_key_id uuid) | ||
| TO bob | ||
| WITH GRANT OPTION; | ||
|
|
||
| REVOKE ALL PRIVILEGES | ||
| ON FUNCTION vault.update_secret (secret_id uuid, new_secret text, new_name text, new_description text, new_key_id uuid) | ||
| FROM PUBLIC; | ||
|
|
||
| GRANT ALL PRIVILEGES | ||
| ON FUNCTION vault.update_secret (secret_id uuid, new_secret text, new_name text, new_description text, new_key_id uuid) | ||
| TO bob | ||
| WITH GRANT OPTION |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.