8000 fix migration (#446) · sorokinvld/postgres@57cff53 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

10000
Appearance settings

Commit 57cff53

Browse files
authored
fix migration (supabase#446)
1 parent 444baf2 commit 57cff53

File tree

4 files changed

+18
-79
lines changed

4 files changed

+18
-79
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323

2424
strategy:
2525
matrix:
26-
supabase-version: ["15.1.0.10-rc1"]
26+
supabase-version: ["15.1.0.11"]
2727
timeout-minutes: 10
2828

2929
services:

migrations/db/migrations/20221207154255_create_pgsodium_and_vault.sql

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@ 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-
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 recreate these objects without also dropping the extension.
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-
$$;
9+
create extension if not exists supabase_vault;
2310

2411
-- migrate:down

migrations/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ version: "3.8"
66

77
services:
88
db:
9-
image: supabase/postgres:15.1.0.10-rc1
9+
image: supabase/postgres:15.1.0.11
1010
restart: "no"
1111
ports:
1212
- 5478:5432

migrations/schema.sql

Lines changed: 15 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -510,25 +510,6 @@ END;
510510
$$;
511511

512512

513-
--
514-
-- Name: key_encrypt_secret(); Type: FUNCTION; Schema: pgsodium; Owner: -
515-
--
516-
517-
CREATE FUNCTION pgsodium.key_encrypt_secret() RETURNS trigger
518-
LANGUAGE plpgsql
519-
AS $$
520-
BEGIN
521-
new.raw_key = CASE WHEN new.raw_key IS NULL THEN NULL ELSE
522-
CASE WHEN new.parent_key IS NULL THEN NULL ELSE
523-
pgsodium.crypto_aead_det_encrypt(new.raw_key::bytea, pg_catalog.convert_to((new.id::text || new.associated_data::text)::text, 'utf8'),
524-
new.parent_key::uuid,
525-
new.raw_key_nonce
526-
) END END;
527-
RETURN new;
528-
END;
529-
$$;
530-
531-
532513
--
533514
-- Name: extension(text); Type: FUNCTION; Schema: storage; Owner: -
534515
--
@@ -597,25 +578,25 @@ $$;
597578

598579

599580
--
600-
-- Name: secrets_encrypt_secret(); Type: FUNCTION; Schema: vault; Owner: -
581+
-- Name: secrets_encrypt_secret_secret(); Type: FUNCTION; Schema: vault; Owner: -
601582
--
602583

603-
CREATE FUNCTION vault.secrets_encrypt_secret() RETURNS trigger
584+
CREATE FUNCTION vault.secrets_encrypt_secret_secret() RETURNS trigger
604585
LANGUAGE plpgsql
605586
AS $$
606-
BEGIN
607-
new.secret = CASE WHEN new.secret IS NULL THEN NULL ELSE
608-
CASE WHEN new.key_id IS NULL THEN NULL ELSE pg_catalog.encode(
609-
pgsodium.crypto_aead_det_encrypt(
610-
pg_catalog.convert_to(new.secret, 'utf8'),
611-
pg_catalog.convert_to((new.id::text || new.description::text || new.created_at::text || new.updated_at::text)::text, 'utf8'),
612-
new.key_id::uuid,
613-
new.nonce
614-
),
615-
'base64') END END;
616-
RETURN new;
617-
END;
618-
$$;
587+
BEGIN
588+
new.secret = CASE WHEN new.secret IS NULL THEN NULL ELSE
589+
CASE WHEN new.key_id IS NULL THEN NULL ELSE pg_catalog.encode(
590+
pgsodium.crypto_aead_det_encrypt(
591+
pg_catalog.convert_to(new.secret, 'utf8'),
592+
pg_catalog.convert_to((new.id::text || new.description::text || new.created_at::text || new.updated_at::text)::text, 'utf8'),
593+
new.key_id::uuid,
594+
new.nonce
595+
),
596+
'base64') END END;
597+
RETURN new;
598+
END;
599+
$$;
619600

620601

621602
SET default_tablespace = '';
@@ -754,35 +735,6 @@ CREATE TABLE auth.users (
754735
COMMENT ON TABLE auth.users IS 'Auth: Stores user login data within a secure schema.';
755736

756737

757-
--
758-
-- Name: decrypted_key; Type: VIEW; Schema: pgsodium; Owner: -
759-
--
760-
761-
CREATE VIEW pgsodium.decrypted_key AS
762-
SELECT key.id,
763-
key.status,
764-
key.created,
765-
key.expires,
766-
key.key_type,
767-
key.key_id,
768-
key.key_context,
769-
key.name,
770-
key.associated_data,
771-
key.raw_key,
772-
CASE
773-
WHEN (key.raw_key IS NULL) THEN NULL::bytea
774-
ELSE
775-
CASE
776-
WHEN (key.parent_key IS NULL) THEN NULL::bytea
777-
ELSE pgsodium.crypto_aead_det_decrypt(key.raw_key, convert_to(((key.id)::text || key.associated_data), 'utf8'::name), key.parent_key, key.raw_key_nonce)
778-
END
779-
END AS decrypted_raw_key,
780-
key.raw_key_nonce,
781-
key.parent_key,
782-
key.comment
783-
FROM pgsodium.key;
784-
785-
786738
--
787739
-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: -
788740
--

0 commit comments

Comments
 (0)
0