Skip to content

Commit a61c1b1

Browse files
committed
chore: move orioledb to extensions scehama
1 parent 73b48db commit a61c1b1

File tree

5 files changed

+87
-150
lines changed

5 files changed

+87
-150
lines changed

migrations/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,18 @@ Additionally, [supabase/postgres](https://github.com/supabase/postgres/blob/deve
7878

7979
### Add a Migration
8080

81+
First, start a local postgres server and apply the migrations
82+
8183
```shell
8284
# Start the database server
83-
docker-compose up
85+
nix run .#dbmate-tool -- --version 15 --flake-url "."
8486

8587
# create a new migration
88+
nix develop
8689
dbmate new '<some message>'
8790
```
8891

89-
Then, populate the migration at `./db/migrations/xxxxxxxxx_<some_message>` and make sure it execute sucessfully with
92+
Then, execute the migration at `./db/migrations/xxxxxxxxx_<some_message>` and make sure it runs sucessfully with
9093

9194
```shell
9295
dbmate up
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- migrate:up
2+
do $$
3+
declare
4+
ext_schema text;
5+
extensions_schema_exists boolean;
6+
begin
7+
-- check if the "extensions" schema exists
8+
select exists (
9+
select 1 from pg_namespace where nspname = 'extensions'
10+
) into extensions_schema_exists;
11+
12+
if extensions_schema_exists then
13+
-- check if the "orioledb" extension is in the "public" schema
14+
select nspname into ext_schema
15+
from pg_extension e
16+
join pg_namespace n on e.extnamespace = n.oid
17+
where extname = 'orioledb';
18+
19+
if ext_schema = 'public' then
20+
execute 'alter extension orioledb set schema extensions';
21+
end if;
22+
end if;
23+
end $$;
24+
25+
-- migrate:down
26+

migrations/schema-15.sql

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -574,28 +574,6 @@ END
574574
$$;
575575

576576

577-
--
578-
-- Name: secrets_encrypt_secret_secret(); Type: FUNCTION; Schema: vault; Owner: -
579-
--
580-
581-
CREATE FUNCTION vault.secrets_encrypt_secret_secret() RETURNS trigger
582-
LANGUAGE plpgsql
583-
AS $$
584-
BEGIN
585-
new.secret = CASE WHEN new.secret IS NULL THEN NULL ELSE
586-
CASE WHEN new.key_id IS NULL THEN NULL ELSE pg_catalog.encode(
587-
pgsodium.crypto_aead_det_encrypt(
588-
pg_catalog.convert_to(new.secret, 'utf8'),
589-
pg_catalog.convert_to((new.id::text || new.description::text || new.created_at::text || new.updated_at::text)::text, 'utf8'),
590-
new.key_id::uuid,
591-
new.nonce
592-
),
593-
'base64') END END;
594-
RETURN new;
595-
END;
596-
$$;
597-
598-
599577
SET default_tablespace = '';
600578

601579
SET default_table_access_method = heap;
@@ -782,30 +760,6 @@ CREATE TABLE storage.objects (
782760
);
783761

784762

785-
--
786-
-- Name: decrypted_secrets; Type: VIEW; Schema: vault; Owner: -
787-
--
788-
789-
CREATE VIEW vault.decrypted_secrets AS
790-
SELECT secrets.id,
791-
secrets.name,
792-
secrets.description,
793-
secrets.secret,
794-
CASE
795-
WHEN (secrets.secret IS NULL) THEN NULL::text
796-
ELSE
797-
CASE
798-
WHEN (secrets.key_id IS NULL) THEN NULL::text
799-
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)
800-
END
801-
END AS decrypted_secret,
802-
secrets.key_id,
803-
secrets.nonce,
804-
secrets.created_at,
805-
secrets.updated_at
806-
FROM vault.secrets;
807-
808-
809763
--
810764
-- Name: refresh_tokens id; Type: DEFAULT; Schema: auth; Owner: -
811765
--

migrations/schema-orioledb-17.sql

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ CREATE SCHEMA vault;
9191
-- Name: orioledb; Type: EXTENSION; Schema: -; Owner: -
9292
--
9393

94-
CREATE EXTENSION IF NOT EXISTS orioledb WITH SCHEMA public;
94+
CREATE EXTENSION IF NOT EXISTS orioledb WITH SCHEMA extensions;
9595

9696

9797
--
@@ -589,28 +589,6 @@ END
589589
$$;
590590

591591

592-
--
593-
-- Name: secrets_encrypt_secret_secret(); Type: FUNCTION; Schema: vault; Owner: -
594-
--
595-
596-
CREATE FUNCTION vault.secrets_encrypt_secret_secret() RETURNS trigger
597-
LANGUAGE plpgsql
598-
AS $$
599-
BEGIN
600-
new.secret = CASE WHEN new.secret IS NULL THEN NULL ELSE
601-
CASE WHEN new.key_id IS NULL THEN NULL ELSE pg_catalog.encode(
602-
pgsodium.crypto_aead_det_encrypt(
603-
pg_catalog.convert_to(new.secret, 'utf8'),
604-
pg_catalog.convert_to((new.id::text || new.description::text || new.created_at::text || new.updated_at::text)::text, 'utf8'),
605-
new.key_id::uuid,
606-
new.nonce
607-
),
608-
'base64') END END;
609-
RETURN new;
610-
END;
611-
$$;
612-
613-
614592
SET default_tablespace = '';
615593

616594
SET default_table_access_method = orioledb;
@@ -797,30 +775,6 @@ CREATE TABLE storage.objects (
797775
);
798776

799777

800-
--
801-
-- Name: decrypted_secrets; Type: VIEW; Schema: vault; Owner: -
802-
--
803-
804-
CREATE VIEW vault.decrypted_secrets AS
805-
SELECT id,
806-
name,
807-
description,
808-
secret,
809-
CASE
810-
WHEN (secret IS NULL) THEN NULL::text
811-
ELSE
812-
CASE
813-
WHEN (key_id IS NULL) THEN NULL::text
814-
ELSE convert_from(pgsodium.crypto_aead_det_decrypt(decode(secret, 'base64'::text), convert_to(((((id)::text || description) || (created_at)::text) || (updated_at)::text), 'utf8'::name), key_id, nonce), 'utf8'::name)
815-
END
816-
END AS decrypted_secret,
817-
key_id,
818-
nonce,
819-
created_at,
820-
updated_at
821-
FROM vault.secrets;
822-
823-
824778
--
825779
-- Name: refresh_tokens id; Type: DEFAULT; Schema: auth; Owner: -
826780
--

0 commit comments

Comments
 (0)