Skip to content
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

fix: Send functions sets topic properly #1286

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/realtime/tenants/migrations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ defmodule Realtime.Tenants.Migrations do
RealtimeSendSetsConfig,
RealtimeSubscriptionUnlogged,
RealtimeSubscriptionLogged,
RemoveUnusedPublications
RemoveUnusedPublications,
RealtimeSendSetsTopicConfig
}

@migrations [
Expand Down Expand Up @@ -135,7 +136,8 @@ defmodule Realtime.Tenants.Migrations do
{20_241_224_161_212, RealtimeSendSetsConfig},
{20_250_107_150_512, RealtimeSubscriptionUnlogged},
{20_250_110_162_412, RealtimeSubscriptionLogged},
{20_250_123_174_212, RemoveUnusedPublications}
{20_250_123_174_212, RemoveUnusedPublications},
{20_250_128_220_012, RealtimeSendSetsTopicConfig}
]

defstruct [:tenant_external_id, :settings]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
defmodule Realtime.Tenants.Migrations.RealtimeSendSetsTopicConfig 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 $$
BEGIN
BEGIN
-- Set the topic configuration
EXECUTE format('SET LOCAL realtime.topic TO %L', topic);

-- Attempt to insert the message
INSERT INTO realtime.messages (payload, event, topic, private, extension)
VALUES (payload, event, topic, private, 'broadcast');
EXCEPTION
WHEN OTHERS THEN
-- Capture and notify the error
PERFORM pg_notify(
'realtime:system',
jsonb_build_object(
'error', SQLERRM,
'function', 'realtime.send',
'event', event,
'topic', topic,
'private', private
)::text
);
END;
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.34.11",
version: "2.34.12",
elixir: "~> 1.17.3",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down
Loading