-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #241 from commanded/bug/postgres-trigger
Fix bug with subscriptions trigger in older Postgres versions
- Loading branch information
Showing
9 changed files
with
62 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[ | ||
{"deps/postgrex/lib/postgrex/type_module.ex", :improper_list_constr}, | ||
{"lib/postgrex/type_module.ex", :improper_list_constr} | ||
] |
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
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
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
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
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
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,36 @@ | ||
DO $migration$ | ||
BEGIN | ||
CREATE OR REPLACE FUNCTION notify_events() | ||
RETURNS trigger AS $$ | ||
DECLARE | ||
old_stream_version bigint; | ||
channel text; | ||
payload text; | ||
BEGIN | ||
-- Payload text contains: | ||
-- * `stream_uuid` | ||
-- * `stream_id` | ||
-- * first `stream_version` | ||
-- * last `stream_version` | ||
-- Each separated by a comma (e.g. 'stream-12345,1,1,5') | ||
|
||
IF TG_OP = 'UPDATE' THEN | ||
old_stream_version := OLD.stream_version + 1; | ||
ELSE | ||
old_stream_version := 1; | ||
END IF; | ||
|
||
channel := TG_TABLE_SCHEMA || '.events'; | ||
payload := NEW.stream_uuid || ',' || NEW.stream_id || ',' || old_stream_version || ',' || NEW.stream_version; | ||
|
||
-- Notify events to listeners | ||
PERFORM pg_notify(channel, payload); | ||
|
||
RETURN NULL; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
-- Record schema migration | ||
INSERT INTO schema_migrations (major_version, minor_version, patch_version) VALUES (1, 3, 2); | ||
END; | ||
$migration$ LANGUAGE plpgsql; |
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
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