-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: realtime schema prefix not set in send function (#1232)
- Loading branch information
1 parent
83c756d
commit 274166a
Showing
3 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
lib/realtime/tenants/repo/migrations/20241121104152_fix_send_function_.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters