Skip to content

Commit edf49b3

Browse files
committed
add schema to oriole
1 parent 1b582dd commit edf49b3

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
nix/checks.nix
3131
nix/config.nix
3232
nix/devShells.nix
33+
nix/pgbouncer.nix
3334
nix/ext
3435
nix/fmt.nix
3536
nix/hooks.nix

migrations/schema-orioledb-17.sql

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,106 @@ CREATE SCHEMA realtime;
6565

6666
CREATE SCHEMA storage;
6767

68+
--
69+
-- Name: supabase_subscription_mgmt; Type: SCHEMA; Schema: -; Owner: -
70+
--
71+
72+
CREATE SCHEMA supabase_subscription_mgmt;
73+
74+
75+
--
76+
-- Name: pg_alter_subscription_disable(text); Type: FUNCTION; Schema: supabase_subscription_mgmt; Owner: -
77+
--
78+
79+
CREATE FUNCTION supabase_subscription_mgmt.pg_alter_subscription_disable(arg_subscription_name text) RETURNS void
80+
LANGUAGE plpgsql SECURITY DEFINER
81+
SET search_path TO 'pg_catalog'
82+
AS $$
83+
begin
84+
execute pg_catalog.format('alter subscription %I disable', arg_subscription_name);
85+
end;
86+
$$;
87+
88+
89+
--
90+
-- Name: pg_alter_subscription_enable(text); Type: FUNCTION; Schema: supabase_subscription_mgmt; Owner: -
91+
--
92+
93+
CREATE FUNCTION supabase_subscription_mgmt.pg_alter_subscription_enable(arg_subscription_name text) RETURNS void
94+
LANGUAGE plpgsql SECURITY DEFINER
95+
SET search_path TO 'pg_catalog', 'supabase_subscription_mgmt'
96+
AS $$
97+
begin
98+
execute pg_catalog.format('alter subscription %I enable', arg_subscription_name);
99+
end;
100+
$$;
101+
102+
103+
--
104+
-- Name: pg_create_subscription(text, text, text, text, boolean, text); Type: FUNCTION; Schema: supabase_subscription_mgmt; Owner: -
105+
--
106+
107+
CREATE FUNCTION supabase_subscription_mgmt.pg_create_subscription(arg_subscription_name text, arg_connection_string text, arg_publication_name text, arg_slot_name text, arg_copy_data boolean DEFAULT true, arg_origin text DEFAULT 'any'::text) RETURNS void
108+
LANGUAGE plpgsql SECURITY DEFINER
109+
SET search_path TO 'pg_catalog', 'supabase_subscription_mgmt'
110+
AS $$
111+
declare
112+
pg_version int;
113+
create_subscription_cmd text;
114+
begin
115+
-- get the postgresql version
116+
select current_setting('server_version_num')::int into pg_version;
117+
118+
if pg_version < 160000 and arg_origin <> 'any' then
119+
raise exception 'postgresql version must be 16 or higher to specify origin other than "any". current version: %', pg_version;
120+
end if;
121+
122+
if arg_origin <> 'any' and arg_origin <> 'none' then
123+
raise exception 'invalid origin: %. origin must be either "any" or "none".', arg_origin;
124+
end if;
125+
126+
-- pg16 and later: include the origin parameter only if it's 'none', as its default is any
127+
if pg_version >= 160000 and arg_origin = 'none' then
128+
create_subscription_cmd := pg_catalog.format(
129+
'create subscription %I connection %L publication %I with (slot_name=%L, create_slot=false, copy_data=%s, origin=%L)',
130+
arg_subscription_name, arg_connection_string, arg_publication_name, arg_slot_name, arg_copy_data::text, arg_origin);
131+
else
132+
create_subscription_cmd := pg_catalog.format(
133+
'create subscription %I connection %L publication %I with (slot_name=%L, create_slot=false, copy_data=%s)',
134+
arg_subscription_name, arg_connection_string, arg_publication_name, arg_slot_name, arg_copy_data::text);
135+
end if;
136+
137+
-- execute the create subscription command
138+
execute create_subscription_cmd;
139+
end;
140+
$$;
141+
142+
143+
--
144+
-- Name: pg_drop_subscription(text); Type: FUNCTION; Schema: supabase_subscription_mgmt; Owner: -
145+
--
146+
147+
CREATE FUNCTION supabase_subscription_mgmt.pg_drop_subscription(arg_subscription_name text) RETURNS void
148+
LANGUAGE plpgsql SECURITY DEFINER
149+
SET search_path TO 'pg_catalog', 'supabase_subscription_mgmt'
150+
AS $$
151+
declare
152+
l_slot_name text;
153+
l_subconninfo text;
154+
begin
155+
select subslotname, subconninfo
156+
into l_slot_name, l_subconninfo
157+
from pg_catalog.pg_subscription
158+
where subname = arg_subscription_name;
159+
if l_slot_name is null and l_subconninfo is null then
160+
raise exception 'no subscription found for name: %', arg_subscription_name;
161+
end if;
162+
execute pg_catalog.format('alter subscription %I disable', arg_subscription_name);
163+
execute pg_catalog.format('alter subscription %I set (slot_name = none)', arg_subscription_name);
164+
execute pg_catalog.format('drop subscription %I', arg_subscription_name);
165+
end;
166+
$$;
167+
68168

69169
--
70170
-- Name: vault; Type: SCHEMA; Schema: -; Owner: -

0 commit comments

Comments
 (0)