mirror of
https://github.com/Diggsey/sqlxmq.git
synced 2024-11-22 00:01:00 +00:00
Fix bug with mq_latest_message
where the wrong message may be returned
if multiple messages have the exact same creation date.
This commit is contained in:
parent
59adc6313f
commit
15cafb3590
6 changed files with 71 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "sqlxmq"
|
name = "sqlxmq"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
authors = ["Diggory Blake <diggsey@googlemail.com>"]
|
authors = ["Diggory Blake <diggsey@googlemail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
@ -23,7 +23,7 @@ uuid = { version = "0.8.2", features = ["v4"] }
|
||||||
log = "0.4.14"
|
log = "0.4.14"
|
||||||
serde_json = "1.0.64"
|
serde_json = "1.0.64"
|
||||||
serde = "1.0.124"
|
serde = "1.0.124"
|
||||||
sqlxmq_macros = { version = "0.3.1", path = "sqlxmq_macros" }
|
sqlxmq_macros = { version = "0.3.2", path = "sqlxmq_macros" }
|
||||||
anymap2 = "0.13.0"
|
anymap2 = "0.13.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|
15
migrations/20211013151757_fix_mq_latest_message.down.sql
Normal file
15
migrations/20211013151757_fix_mq_latest_message.down.sql
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
CREATE OR REPLACE FUNCTION mq_latest_message(from_channel_name TEXT, from_channel_args TEXT)
|
||||||
|
RETURNS UUID AS $$
|
||||||
|
SELECT COALESCE(
|
||||||
|
(
|
||||||
|
SELECT id FROM mq_msgs
|
||||||
|
WHERE channel_name = from_channel_name
|
||||||
|
AND channel_args = from_channel_args
|
||||||
|
AND after_message_id IS NOT NULL
|
||||||
|
AND id != uuid_nil()
|
||||||
|
ORDER BY created_at DESC, id DESC
|
||||||
|
LIMIT 1
|
||||||
|
),
|
||||||
|
uuid_nil()
|
||||||
|
)
|
||||||
|
$$ LANGUAGE SQL STABLE;
|
19
migrations/20211013151757_fix_mq_latest_message.up.sql
Normal file
19
migrations/20211013151757_fix_mq_latest_message.up.sql
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
CREATE OR REPLACE FUNCTION mq_latest_message(from_channel_name TEXT, from_channel_args TEXT)
|
||||||
|
RETURNS UUID AS $$
|
||||||
|
SELECT COALESCE(
|
||||||
|
(
|
||||||
|
SELECT id FROM mq_msgs
|
||||||
|
WHERE channel_name = from_channel_name
|
||||||
|
AND channel_args = from_channel_args
|
||||||
|
AND after_message_id IS NOT NULL
|
||||||
|
AND id != uuid_nil()
|
||||||
|
AND NOT EXISTS(
|
||||||
|
SELECT * FROM mq_msgs AS mq_msgs2
|
||||||
|
WHERE mq_msgs2.after_message_id = mq_msgs.id
|
||||||
|
)
|
||||||
|
ORDER BY created_at DESC
|
||||||
|
LIMIT 1
|
||||||
|
),
|
||||||
|
uuid_nil()
|
||||||
|
)
|
||||||
|
$$ LANGUAGE SQL STABLE;
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "sqlxmq_macros"
|
name = "sqlxmq_macros"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
authors = ["Diggory Blake <diggsey@googlemail.com>"]
|
authors = ["Diggory Blake <diggsey@googlemail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
CREATE OR REPLACE FUNCTION mq_latest_message(from_channel_name TEXT, from_channel_args TEXT)
|
||||||
|
RETURNS UUID AS $$
|
||||||
|
SELECT COALESCE(
|
||||||
|
(
|
||||||
|
SELECT id FROM mq_msgs
|
||||||
|
WHERE channel_name = from_channel_name
|
||||||
|
AND channel_args = from_channel_args
|
||||||
|
AND after_message_id IS NOT NULL
|
||||||
|
AND id != uuid_nil()
|
||||||
|
ORDER BY created_at DESC, id DESC
|
||||||
|
LIMIT 1
|
||||||
|
),
|
||||||
|
uuid_nil()
|
||||||
|
)
|
||||||
|
$$ LANGUAGE SQL STABLE;
|
|
@ -0,0 +1,19 @@
|
||||||
|
CREATE OR REPLACE FUNCTION mq_latest_message(from_channel_name TEXT, from_channel_args TEXT)
|
||||||
|
RETURNS UUID AS $$
|
||||||
|
SELECT COALESCE(
|
||||||
|
(
|
||||||
|
SELECT id FROM mq_msgs
|
||||||
|
WHERE channel_name = from_channel_name
|
||||||
|
AND channel_args = from_channel_args
|
||||||
|
AND after_message_id IS NOT NULL
|
||||||
|
AND id != uuid_nil()
|
||||||
|
AND NOT EXISTS(
|
||||||
|
SELECT * FROM mq_msgs AS mq_msgs2
|
||||||
|
WHERE mq_msgs2.after_message_id = mq_msgs.id
|
||||||
|
)
|
||||||
|
ORDER BY created_at DESC
|
||||||
|
LIMIT 1
|
||||||
|
),
|
||||||
|
uuid_nil()
|
||||||
|
)
|
||||||
|
$$ LANGUAGE SQL STABLE;
|
Loading…
Reference in a new issue