Skip to content

Commit

Permalink
fix: realtime schema prefix not set in send function (#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipecabaco authored Nov 21, 2024
1 parent 83c756d commit 274166a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/realtime/tenants/migrations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ defmodule Realtime.Tenants.Migrations do
ChangeMessagesIdType,
UuidAutoGeneration,
MessagesPartitioning,
MessagesUsingUuid
MessagesUsingUuid,
FixSendFunction
}

@migrations [
Expand Down Expand Up @@ -120,7 +121,8 @@ defmodule Realtime.Tenants.Migrations do
{20_240_919_163_305, ChangeMessagesIdType},
{20_241_019_105_805, UuidAutoGeneration},
{20_241_030_150_047, MessagesPartitioning},
{20_241_108_114_728, MessagesUsingUuid}
{20_241_108_114_728, MessagesUsingUuid},
{20_241_121_104_152, FixSendFunction}
]

defstruct [:tenant_external_id, :settings]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
defmodule Realtime.Tenants.Migrations.FixSendFunction do
@moduledoc false
use Ecto.Migration

# We missed the schema prefix of `realtime.` in the create table partition statement
def change do
execute("""
CREATE OR REPLACE FUNCTION realtime.send(payload jsonb, event text, topic text, private boolean DEFAULT true)
RETURNS void
AS $$
DECLARE
partition_name text;
BEGIN
partition_name := 'messages_' || to_char(NOW(), 'YYYY_MM_DD');
IF NOT EXISTS (
SELECT 1
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname = 'realtime'
AND c.relname = partition_name
) THEN
EXECUTE format(
'CREATE TABLE realtime.%I PARTITION OF realtime.messages FOR VALUES FROM (%L) TO (%L)',
partition_name,
NOW(),
(NOW() + interval '1 day')::timestamp
);
END IF;
INSERT INTO realtime.messages (payload, event, topic, private, extension)
VALUES (payload, event, topic, private, 'broadcast');
END;
$$
LANGUAGE plpgsql;
""")
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Realtime.MixProject do
def project do
[
app: :realtime,
version: "2.33.52",
version: "2.33.53",
elixir: "~> 1.16.0",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down

0 comments on commit 274166a

Please sign in to comment.