{ "(repeated)": [ {"sql":"-- The devices table and its indexes.\ncreate schema if not exists \"notifications\";\ncreate table \"notifications\".\"devices\" (\n \"id\" uuid primary key,\n \"user_id\" text not null,\n \"kind\" text not null check (\"kind\" in ('web', 'apns', 'fcm', 'relay')),\n \"token\" text not null,\n \"p256dh\" text,\n \"auth\" text,\n \"environment\" text check (\"environment\" in ('sandbox', 'production')),\n \"app_id\" text,\n \"user_agent\" text,\n \"session_id\" text,\n \"created_at\" timestamptz not null,\n \"last_seen_at\" timestamptz not null,\n check (\n (\"kind\" = 'web' and \"p256dh\" is not null and \"auth\" is not null and \"environment\" is null and \"app_id\" is null)\n or (\"kind\" = 'apns' and \"p256dh\" is null and \"auth\" is null and \"environment\" is not null and \"app_id\" is not null)\n or (\"kind\" = 'fcm' and \"p256dh\" is null and \"auth\" is null and \"environment\" is null)\n or (\"kind\" = 'relay' and \"p256dh\" is null and \"auth\" is null and \"environment\" is null and \"app_id\" is null)\n )\n);\ncreate unique index on \"notifications\".\"devices\" (\"token\");\ncreate index on \"notifications\".\"devices\" (\"user_id\");\n\n-- The history table and its indexes.\ncreate schema if not exists \"notifications\";\ncreate table \"notifications\".\"history\" (\n \"id\" uuid primary key,\n \"user_id\" text not null,\n \"title\" text not null,\n \"body\" text,\n \"url\" text,\n \"data\" jsonb,\n \"created_at\" timestamptz not null,\n \"read_at\" timestamptz\n);\ncreate index on \"notifications\".\"history\" (\"user_id\", \"created_at\" desc, \"id\" desc);\ncreate index on \"notifications\".\"history\" (\"user_id\", \"created_at\") where \"read_at\" is null;","result":[{"command":"CREATE","rowCount":null,"columns":[],"rows":[]},{"command":"CREATE","rowCount":null,"columns":[],"rows":[]},{"command":"CREATE","rowCount":null,"columns":[],"rows":[]},{"command":"CREATE","rowCount":null,"columns":[],"rows":[]},{"command":"CREATE","rowCount":null,"columns":[],"rows":[]},{"command":"CREATE","rowCount":null,"columns":[],"rows":[]},{"command":"CREATE","rowCount":null,"columns":[],"rows":[]},{"command":"CREATE","rowCount":null,"columns":[],"rows":[]}]} ], "the send job on Postgres > keeps the history once, removes a gone device, retries only the device that asked, then drops the message": { "the send job on Postgres > keeps the history once, removes a gone device, retries only the device that asked, then drops the message#0": [ {"repeated":0}, {"sql":"create table people (id text primary key); insert into people values ('a'), ('b')","result":[{"command":"CREATE","rowCount":null,"columns":[],"rows":[]},{"command":"INSERT","rowCount":2,"columns":[],"rows":[]}]}, {"sql":"alter table notifications.history add foreign key (user_id) references people (id) on delete cascade","result":{"command":"ALTER","rowCount":null,"columns":[],"rows":[]}}, {"sql":"insert into \"notifications\".\"devices\" as d (\"id\", \"user_id\", \"kind\", \"token\", \"p256dh\", \"auth\", \"environment\", \"app_id\", \"user_agent\", \"session_id\", \"created_at\", \"last_seen_at\") values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)\n on conflict (\"token\") do update set \"id\" = case when \"d\".\"user_id\" = excluded.\"user_id\" then \"d\".\"id\" else excluded.\"id\" end, \"created_at\" = case when \"d\".\"user_id\" = excluded.\"user_id\" then \"d\".\"created_at\" else excluded.\"created_at\" end, \"user_id\" = excluded.\"user_id\", \"kind\" = excluded.\"kind\", \"p256dh\" = excluded.\"p256dh\", \"auth\" = excluded.\"auth\", \"environment\" = excluded.\"environment\", \"app_id\" = excluded.\"app_id\", \"user_agent\" = excluded.\"user_agent\", \"session_id\" = excluded.\"session_id\", \"last_seen_at\" = excluded.\"last_seen_at\"\n where \"d\".\"user_id\" = excluded.\"user_id\" or (\"d\".\"kind\" <> 'web' and excluded.\"kind\" <> 'web')\n returning \"id\" as \"id\", \"user_id\" as \"user_id\", \"kind\" as \"kind\", \"token\" as \"token\", \"p256dh\" as \"p256dh\", \"auth\" as \"auth\", \"environment\" as \"environment\", \"app_id\" as \"app_id\", \"user_agent\" as \"user_agent\", \"session_id\" as \"session_id\", \"created_at\" as \"created_at\", \"last_seen_at\" as \"last_seen_at\"","params":["34db7c02-2036-444a-a4aa-01786fa52a08","a","web","https://fcm.googleapis.com/fcm/send/a-ok","BG_wO5SSQc4drdQ1GeaWDgqFtBppoFwygQOqK84VlMoWPE91OlW_AdxT9sCwx-7ni0DG_30lqW4igrmJzvccFEo","AgICAgICAgICAgICAgICAg",null,null,null,null,"2026-08-01T00:00:00.000+00:00","2026-08-01T00:00:00.000+00:00"],"result":{"command":"INSERT","rowCount":1,"columns":[["id",2950],["user_id",25],["kind",25],["token",25],["p256dh",25],["auth",25],["environment",25],["app_id",25],["user_agent",25],["session_id",25],["created_at",1184],["last_seen_at",1184]],"rows":[["34db7c02-2036-444a-a4aa-01786fa52a08","a","web","https://fcm.googleapis.com/fcm/send/a-ok","BG_wO5SSQc4drdQ1GeaWDgqFtBppoFwygQOqK84VlMoWPE91OlW_AdxT9sCwx-7ni0DG_30lqW4igrmJzvccFEo","AgICAgICAgICAgICAgICAg",null,null,null,null,"2026-08-01 00:00:00+00","2026-08-01 00:00:00+00"]]}}, {"sql":"insert into \"notifications\".\"devices\" as d (\"id\", \"user_id\", \"kind\", \"token\", \"p256dh\", \"auth\", \"environment\", \"app_id\", \"user_agent\", \"session_id\", \"created_at\", \"last_seen_at\") values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)\n on conflict (\"token\") do update set \"id\" = case when \"d\".\"user_id\" = excluded.\"user_id\" then \"d\".\"id\" else excluded.\"id\" end, \"created_at\" = case when \"d\".\"user_id\" = excluded.\"user_id\" then \"d\".\"created_at\" else excluded.\"created_at\" end, \"user_id\" = excluded.\"user_id\", \"kind\" = excluded.\"kind\", \"p256dh\" = excluded.\"p256dh\", \"auth\" = excluded.\"auth\", \"environment\" = excluded.\"environment\", \"app_id\" = excluded.\"app_id\", \"user_agent\" = excluded.\"user_agent\", \"session_id\" = excluded.\"session_id\", \"last_seen_at\" = excluded.\"last_seen_at\"\n where \"d\".\"user_id\" = excluded.\"user_id\" or (\"d\".\"kind\" <> 'web' and excluded.\"kind\" <> 'web')\n returning \"id\" as \"id\", \"user_id\" as \"user_id\", \"kind\" as \"kind\", \"token\" as \"token\", \"p256dh\" as \"p256dh\", \"auth\" as \"auth\", \"environment\" as \"environment\", \"app_id\" as \"app_id\", \"user_agent\" as \"user_agent\", \"session_id\" as \"session_id\", \"created_at\" as \"created_at\", \"last_seen_at\" as \"last_seen_at\"","params":["cc8fa173-065a-416c-b732-e5809f982be7","a","web","https://fcm.googleapis.com/fcm/send/a-gone","BG_wO5SSQc4drdQ1GeaWDgqFtBppoFwygQOqK84VlMoWPE91OlW_AdxT9sCwx-7ni0DG_30lqW4igrmJzvccFEo","AgICAgICAgICAgICAgICAg",null,null,null,null,"2026-08-01T00:00:00.000+00:00","2026-08-01T00:00:00.000+00:00"],"result":{"command":"INSERT","rowCount":1,"columns":[["id",2950],["user_id",25],["kind",25],["token",25],["p256dh",25],["auth",25],["environment",25],["app_id",25],["user_agent",25],["session_id",25],["created_at",1184],["last_seen_at",1184]],"rows":[["cc8fa173-065a-416c-b732-e5809f982be7","a","web","https://fcm.googleapis.com/fcm/send/a-gone","BG_wO5SSQc4drdQ1GeaWDgqFtBppoFwygQOqK84VlMoWPE91OlW_AdxT9sCwx-7ni0DG_30lqW4igrmJzvccFEo","AgICAgICAgICAgICAgICAg",null,null,null,null,"2026-08-01 00:00:00+00","2026-08-01 00:00:00+00"]]}}, {"sql":"insert into \"notifications\".\"devices\" as d (\"id\", \"user_id\", \"kind\", \"token\", \"p256dh\", \"auth\", \"environment\", \"app_id\", \"user_agent\", \"session_id\", \"created_at\", \"last_seen_at\") values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)\n on conflict (\"token\") do update set \"id\" = case when \"d\".\"user_id\" = excluded.\"user_id\" then \"d\".\"id\" else excluded.\"id\" end, \"created_at\" = case when \"d\".\"user_id\" = excluded.\"user_id\" then \"d\".\"created_at\" else excluded.\"created_at\" end, \"user_id\" = excluded.\"user_id\", \"kind\" = excluded.\"kind\", \"p256dh\" = excluded.\"p256dh\", \"auth\" = excluded.\"auth\", \"environment\" = excluded.\"environment\", \"app_id\" = excluded.\"app_id\", \"user_agent\" = excluded.\"user_agent\", \"session_id\" = excluded.\"session_id\", \"last_seen_at\" = excluded.\"last_seen_at\"\n where \"d\".\"user_id\" = excluded.\"user_id\" or (\"d\".\"kind\" <> 'web' and excluded.\"kind\" <> 'web')\n returning \"id\" as \"id\", \"user_id\" as \"user_id\", \"kind\" as \"kind\", \"token\" as \"token\", \"p256dh\" as \"p256dh\", \"auth\" as \"auth\", \"environment\" as \"environment\", \"app_id\" as \"app_id\", \"user_agent\" as \"user_agent\", \"session_id\" as \"session_id\", \"created_at\" as \"created_at\", \"last_seen_at\" as \"last_seen_at\"","params":["85de8598-8bad-4558-ab4e-11440901106c","b","web","https://fcm.googleapis.com/fcm/send/b-busy","BG_wO5SSQc4drdQ1GeaWDgqFtBppoFwygQOqK84VlMoWPE91OlW_AdxT9sCwx-7ni0DG_30lqW4igrmJzvccFEo","AgICAgICAgICAgICAgICAg",null,null,null,null,"2026-08-01T00:00:00.000+00:00","2026-08-01T00:00:00.000+00:00"],"result":{"command":"INSERT","rowCount":1,"columns":[["id",2950],["user_id",25],["kind",25],["token",25],["p256dh",25],["auth",25],["environment",25],["app_id",25],["user_agent",25],["session_id",25],["created_at",1184],["last_seen_at",1184]],"rows":[["85de8598-8bad-4558-ab4e-11440901106c","b","web","https://fcm.googleapis.com/fcm/send/b-busy","BG_wO5SSQc4drdQ1GeaWDgqFtBppoFwygQOqK84VlMoWPE91OlW_AdxT9sCwx-7ni0DG_30lqW4igrmJzvccFEo","AgICAgICAgICAgICAgICAg",null,null,null,null,"2026-08-01 00:00:00+00","2026-08-01 00:00:00+00"]]}}, {"sql":"select jobs.enqueue($1, $2::jsonb) as id","params":["notifications.send","{\"to\":{\"userIds\":[\"a\",\"b\",\"deleted\"],\"inbox\":true},\"message\":{\"title\":\"Update\",\"url\":\"https://app.example/x\"}}"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",2950]],"rows":[["{{uuid:1:4}}"]]}}, {"sql":"update jobs.job set state = 'active', started_on = now() + $1::interval, retry_count = $2 where id = $3::uuid returning data, started_on","params":["1 seconds","0","{{uuid:1:4}}"],"result":{"command":"UPDATE","rowCount":1,"columns":[["data",3802],["started_on",1184]],"rows":[["{\"to\": {\"inbox\": true, \"userIds\": [\"a\", \"b\", \"deleted\"]}, \"message\": {\"url\": \"https://app.example/x\", \"title\": \"Update\"}}","{{now:1: :-:+00}}"]]}}, {"sql":"begin","result":{"command":"BEGIN","rowCount":null,"columns":[],"rows":[]}}, {"sql":"insert into \"notifications\".\"history\" (\"id\", \"user_id\", \"title\", \"body\", \"url\", \"data\", \"created_at\", \"read_at\") values ($1, $2, $3, $4, $5, $6::jsonb, $7, $8) returning \"id\" as \"id\", \"user_id\" as \"user_id\", \"title\" as \"title\", \"body\" as \"body\", \"url\" as \"url\", \"data\" as \"data\", \"created_at\" as \"created_at\", \"read_at\" as \"read_at\"","params":["b91779b2-efc4-4300-bfad-6401c7b12c13","a","Update",null,"https://app.example/x",null,"2026-08-01T00:00:00.000+00:00",null],"result":{"command":"INSERT","rowCount":1,"columns":[["id",2950],["user_id",25],["title",25],["body",25],["url",25],["data",3802],["created_at",1184],["read_at",1184]],"rows":[["b91779b2-efc4-4300-bfad-6401c7b12c13","a","Update",null,"https://app.example/x",null,"2026-08-01 00:00:00+00",null]]}}, {"sql":"update \"jobs\".\"job\" set data = jsonb_set(data, '{progress}', $1::jsonb) where name = $2 and id = $3::uuid and state = 'active' and started_on > $4::timestamptz - interval '1 millisecond' and started_on < $5::timestamptz + interval '1 millisecond'","params":["{\"recorded\":[\"a\"],\"done\":[],\"retried\":[]}","notifications.send","{{uuid:1:4}}","{{now:1:T:3:+00:00}}","{{now:1:T:3:+00:00}}"],"result":{"command":"UPDATE","rowCount":1,"columns":[],"rows":[]}}, {"sql":"commit","result":{"command":"COMMIT","rowCount":null,"columns":[],"rows":[]}}, {"sql":"select \"id\" as \"id\", \"user_id\" as \"user_id\", \"kind\" as \"kind\", \"token\" as \"token\", \"p256dh\" as \"p256dh\", \"auth\" as \"auth\", \"environment\" as \"environment\", \"app_id\" as \"app_id\", \"user_agent\" as \"user_agent\", \"session_id\" as \"session_id\", \"created_at\" as \"created_at\", \"last_seen_at\" as \"last_seen_at\" from \"notifications\".\"devices\" where \"user_id\" = $1 order by \"last_seen_at\" desc","params":["a"],"result":{"command":"SELECT","rowCount":2,"columns":[["id",2950],["user_id",25],["kind",25],["token",25],["p256dh",25],["auth",25],["environment",25],["app_id",25],["user_agent",25],["session_id",25],["created_at",1184],["last_seen_at",1184]],"rows":[ ["34db7c02-2036-444a-a4aa-01786fa52a08","a","web","https://fcm.googleapis.com/fcm/send/a-ok","BG_wO5SSQc4drdQ1GeaWDgqFtBppoFwygQOqK84VlMoWPE91OlW_AdxT9sCwx-7ni0DG_30lqW4igrmJzvccFEo","AgICAgICAgICAgICAgICAg",null,null,null,null,"2026-08-01 00:00:00+00","2026-08-01 00:00:00+00"], ["cc8fa173-065a-416c-b732-e5809f982be7","a","web","https://fcm.googleapis.com/fcm/send/a-gone","BG_wO5SSQc4drdQ1GeaWDgqFtBppoFwygQOqK84VlMoWPE91OlW_AdxT9sCwx-7ni0DG_30lqW4igrmJzvccFEo","AgICAgICAgICAgICAgICAg",null,null,null,null,"2026-08-01 00:00:00+00","2026-08-01 00:00:00+00"] ]}}, {"sql":"select 1 from \"jobs\".\"job\" where name = $1 and id = $2::uuid and state = 'active' and started_on > $3::timestamptz - interval '1 millisecond' and started_on < $4::timestamptz + interval '1 millisecond'","params":["notifications.send","{{uuid:1:4}}","{{now:1:T:3:+00:00}}","{{now:1:T:3:+00:00}}"],"result":{"command":"SELECT","rowCount":1,"columns":[["?column?",23]],"rows":[["1"]]}}, {"sql":"update \"jobs\".\"job\" set data = jsonb_set(data, '{progress}', $1::jsonb) where name = $2 and id = $3::uuid and state = 'active' and started_on > $4::timestamptz - interval '1 millisecond' and started_on < $5::timestamptz + interval '1 millisecond'","params":["{\"recorded\":[\"a\"],\"done\":[\"34db7c02-2036-444a-a4aa-01786fa52a08\"],\"retried\":[]}","notifications.send","{{uuid:1:4}}","{{now:1:T:3:+00:00}}","{{now:1:T:3:+00:00}}"],"result":{"command":"UPDATE","rowCount":1,"columns":[],"rows":[]}}, {"sql":"delete from \"notifications\".\"devices\" where \"token\" = any($1::text[])","params":["{\"https://fcm.googleapis.com/fcm/send/a-gone\"}"],"result":{"command":"DELETE","rowCount":1,"columns":[],"rows":[]}}, {"sql":"update \"jobs\".\"job\" set data = jsonb_set(data, '{progress}', $1::jsonb) where name = $2 and id = $3::uuid and state = 'active' and started_on > $4::timestamptz - interval '1 millisecond' and started_on < $5::timestamptz + interval '1 millisecond'","params":["{\"recorded\":[\"a\"],\"done\":[\"34db7c02-2036-444a-a4aa-01786fa52a08\",\"cc8fa173-065a-416c-b732-e5809f982be7\"],\"retried\":[]}","notifications.send","{{uuid:1:4}}","{{now:1:T:3:+00:00}}","{{now:1:T:3:+00:00}}"],"result":{"command":"UPDATE","rowCount":1,"columns":[],"rows":[]}}, {"sql":"begin","result":{"command":"BEGIN","rowCount":null,"columns":[],"rows":[]}}, {"sql":"insert into \"notifications\".\"history\" (\"id\", \"user_id\", \"title\", \"body\", \"url\", \"data\", \"created_at\", \"read_at\") values ($1, $2, $3, $4, $5, $6::jsonb, $7, $8) returning \"id\" as \"id\", \"user_id\" as \"user_id\", \"title\" as \"title\", \"body\" as \"body\", \"url\" as \"url\", \"data\" as \"data\", \"created_at\" as \"created_at\", \"read_at\" as \"read_at\"","params":["13b8e51e-4228-4de4-b98d-17140371156b","b","Update",null,"https://app.example/x",null,"2026-08-01T00:00:00.000+00:00",null],"result":{"command":"INSERT","rowCount":1,"columns":[["id",2950],["user_id",25],["title",25],["body",25],["url",25],["data",3802],["created_at",1184],["read_at",1184]],"rows":[["13b8e51e-4228-4de4-b98d-17140371156b","b","Update",null,"https://app.example/x",null,"2026-08-01 00:00:00+00",null]]}}, {"sql":"update \"jobs\".\"job\" set data = jsonb_set(data, '{progress}', $1::jsonb) where name = $2 and id = $3::uuid and state = 'active' and started_on > $4::timestamptz - interval '1 millisecond' and started_on < $5::timestamptz + interval '1 millisecond'","params":["{\"recorded\":[\"a\",\"b\"],\"done\":[\"34db7c02-2036-444a-a4aa-01786fa52a08\",\"cc8fa173-065a-416c-b732-e5809f982be7\"],\"retried\":[]}","notifications.send","{{uuid:1:4}}","{{now:1:T:3:+00:00}}","{{now:1:T:3:+00:00}}"],"result":{"command":"UPDATE","rowCount":1,"columns":[],"rows":[]}}, {"sql":"commit","result":{"command":"COMMIT","rowCount":null,"columns":[],"rows":[]}}, {"sql":"select \"id\" as \"id\", \"user_id\" as \"user_id\", \"kind\" as \"kind\", \"token\" as \"token\", \"p256dh\" as \"p256dh\", \"auth\" as \"auth\", \"environment\" as \"environment\", \"app_id\" as \"app_id\", \"user_agent\" as \"user_agent\", \"session_id\" as \"session_id\", \"created_at\" as \"created_at\", \"last_seen_at\" as \"last_seen_at\" from \"notifications\".\"devices\" where \"user_id\" = $1 order by \"last_seen_at\" desc","params":["b"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",2950],["user_id",25],["kind",25],["token",25],["p256dh",25],["auth",25],["environment",25],["app_id",25],["user_agent",25],["session_id",25],["created_at",1184],["last_seen_at",1184]],"rows":[["85de8598-8bad-4558-ab4e-11440901106c","b","web","https://fcm.googleapis.com/fcm/send/b-busy","BG_wO5SSQc4drdQ1GeaWDgqFtBppoFwygQOqK84VlMoWPE91OlW_AdxT9sCwx-7ni0DG_30lqW4igrmJzvccFEo","AgICAgICAgICAgICAgICAg",null,null,null,null,"2026-08-01 00:00:00+00","2026-08-01 00:00:00+00"]]}}, {"sql":"select 1 from \"jobs\".\"job\" where name = $1 and id = $2::uuid and state = 'active' and started_on > $3::timestamptz - interval '1 millisecond' and started_on < $4::timestamptz + interval '1 millisecond'","params":["notifications.send","{{uuid:1:4}}","{{now:1:T:3:+00:00}}","{{now:1:T:3:+00:00}}"],"result":{"command":"SELECT","rowCount":1,"columns":[["?column?",23]],"rows":[["1"]]}}, {"sql":"update \"jobs\".\"job\" set data = jsonb_set(data, '{progress}', $1::jsonb) where name = $2 and id = $3::uuid and state = 'active' and started_on > $4::timestamptz - interval '1 millisecond' and started_on < $5::timestamptz + interval '1 millisecond'","params":["{\"recorded\":[\"a\",\"b\"],\"done\":[\"34db7c02-2036-444a-a4aa-01786fa52a08\",\"cc8fa173-065a-416c-b732-e5809f982be7\"],\"retried\":[\"85de8598-8bad-4558-ab4e-11440901106c\"]}","notifications.send","{{uuid:1:4}}","{{now:1:T:3:+00:00}}","{{now:1:T:3:+00:00}}"],"result":{"command":"UPDATE","rowCount":1,"columns":[],"rows":[]}}, {"sql":"begin","result":{"command":"BEGIN","rowCount":null,"columns":[],"rows":[]}}, {"sql":"insert into \"notifications\".\"history\" (\"id\", \"user_id\", \"title\", \"body\", \"url\", \"data\", \"created_at\", \"read_at\") values ($1, $2, $3, $4, $5, $6::jsonb, $7, $8) returning \"id\" as \"id\", \"user_id\" as \"user_id\", \"title\" as \"title\", \"body\" as \"body\", \"url\" as \"url\", \"data\" as \"data\", \"created_at\" as \"created_at\", \"read_at\" as \"read_at\"","params":["358195ed-e107-4045-a3fb-78ac26a7bc99","deleted","Update",null,"https://app.example/x",null,"2026-08-01T00:00:00.000+00:00",null],"error":{"message":"insert or update on table \"history\" violates foreign key constraint \"history_user_id_fkey\"","severity":"ERROR","code":"23503","detail":"Key (user_id)=(deleted) is not present in table \"people\".","schema":"notifications","table":"history","constraint":"history_user_id_fkey"}}, {"sql":"rollback","result":{"command":"ROLLBACK","rowCount":null,"columns":[],"rows":[]}}, {"sql":"update \"jobs\".\"job\" set data = jsonb_set(data, '{progress}', $1::jsonb) where name = $2 and id = $3::uuid and state = 'active' and started_on > $4::timestamptz - interval '1 millisecond' and started_on < $5::timestamptz + interval '1 millisecond'","params":["{\"recorded\":[\"a\",\"b\",\"deleted\"],\"done\":[\"34db7c02-2036-444a-a4aa-01786fa52a08\",\"cc8fa173-065a-416c-b732-e5809f982be7\"],\"retried\":[\"85de8598-8bad-4558-ab4e-11440901106c\"]}","notifications.send","{{uuid:1:4}}","{{now:1:T:3:+00:00}}","{{now:1:T:3:+00:00}}"],"result":{"command":"UPDATE","rowCount":1,"columns":[],"rows":[]}}, {"sql":"select \"id\" as \"id\", \"user_id\" as \"user_id\", \"kind\" as \"kind\", \"token\" as \"token\", \"p256dh\" as \"p256dh\", \"auth\" as \"auth\", \"environment\" as \"environment\", \"app_id\" as \"app_id\", \"user_agent\" as \"user_agent\", \"session_id\" as \"session_id\", \"created_at\" as \"created_at\", \"last_seen_at\" as \"last_seen_at\" from \"notifications\".\"devices\" where \"user_id\" = $1 order by \"last_seen_at\" desc","params":["deleted"],"result":{"command":"SELECT","rowCount":0,"columns":[["id",2950],["user_id",25],["kind",25],["token",25],["p256dh",25],["auth",25],["environment",25],["app_id",25],["user_agent",25],["session_id",25],["created_at",1184],["last_seen_at",1184]],"rows":[]}}, {"sql":"select \"id\" as \"id\", \"user_id\" as \"user_id\", \"kind\" as \"kind\", \"token\" as \"token\", \"p256dh\" as \"p256dh\", \"auth\" as \"auth\", \"environment\" as \"environment\", \"app_id\" as \"app_id\", \"user_agent\" as \"user_agent\", \"session_id\" as \"session_id\", \"created_at\" as \"created_at\", \"last_seen_at\" as \"last_seen_at\" from \"notifications\".\"devices\" where \"user_id\" = $1 order by \"last_seen_at\" desc","params":["a"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",2950],["user_id",25],["kind",25],["token",25],["p256dh",25],["auth",25],["environment",25],["app_id",25],["user_agent",25],["session_id",25],["created_at",1184],["last_seen_at",1184]],"rows":[["34db7c02-2036-444a-a4aa-01786fa52a08","a","web","https://fcm.googleapis.com/fcm/send/a-ok","BG_wO5SSQc4drdQ1GeaWDgqFtBppoFwygQOqK84VlMoWPE91OlW_AdxT9sCwx-7ni0DG_30lqW4igrmJzvccFEo","AgICAgICAgICAgICAgICAg",null,null,null,null,"2026-08-01 00:00:00+00","2026-08-01 00:00:00+00"]]}}, {"sql":"select data from jobs.job where id = $1::uuid","params":["{{uuid:1:4}}"],"result":{"command":"SELECT","rowCount":1,"columns":[["data",3802]],"rows":[["{\"to\": {\"inbox\": true, \"userIds\": [\"a\", \"b\", \"deleted\"]}, \"message\": {\"url\": \"https://app.example/x\", \"title\": \"Update\"}, \"progress\": {\"done\": [\"34db7c02-2036-444a-a4aa-01786fa52a08\", \"cc8fa173-065a-416c-b732-e5809f982be7\"], \"retried\": [\"85de8598-8bad-4558-ab4e-11440901106c\"], \"recorded\": [\"a\", \"b\", \"deleted\"]}}"]]}}, {"sql":"update jobs.job set state = 'active', started_on = now() + $1::interval, retry_count = $2 where id = $3::uuid returning data, started_on","params":["2 seconds","1","{{uuid:1:4}}"],"result":{"command":"UPDATE","rowCount":1,"columns":[["data",3802],["started_on",1184]],"rows":[["{\"to\": {\"inbox\": true, \"userIds\": [\"a\", \"b\", \"deleted\"]}, \"message\": {\"url\": \"https://app.example/x\", \"title\": \"Update\"}, \"progress\": {\"done\": [\"34db7c02-2036-444a-a4aa-01786fa52a08\", \"cc8fa173-065a-416c-b732-e5809f982be7\"], \"retried\": [\"85de8598-8bad-4558-ab4e-11440901106c\"], \"recorded\": [\"a\", \"b\", \"deleted\"]}}","{{now:2: :-:+00}}"]]}}, {"sql":"select \"id\" as \"id\", \"user_id\" as \"user_id\", \"kind\" as \"kind\", \"token\" as \"token\", \"p256dh\" as \"p256dh\", \"auth\" as \"auth\", \"environment\" as \"environment\", \"app_id\" as \"app_id\", \"user_agent\" as \"user_agent\", \"session_id\" as \"session_id\", \"created_at\" as \"created_at\", \"last_seen_at\" as \"last_seen_at\" from \"notifications\".\"devices\" where \"user_id\" = $1 order by \"last_seen_at\" desc","params":["a"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",2950],["user_id",25],["kind",25],["token",25],["p256dh",25],["auth",25],["environment",25],["app_id",25],["user_agent",25],["session_id",25],["created_at",1184],["last_seen_at",1184]],"rows":[["34db7c02-2036-444a-a4aa-01786fa52a08","a","web","https://fcm.googleapis.com/fcm/send/a-ok","BG_wO5SSQc4drdQ1GeaWDgqFtBppoFwygQOqK84VlMoWPE91OlW_AdxT9sCwx-7ni0DG_30lqW4igrmJzvccFEo","AgICAgICAgICAgICAgICAg",null,null,null,null,"2026-08-01 00:00:00+00","2026-08-01 00:00:00+00"]]}}, {"sql":"select \"id\" as \"id\", \"user_id\" as \"user_id\", \"kind\" as \"kind\", \"token\" as \"token\", \"p256dh\" as \"p256dh\", \"auth\" as \"auth\", \"environment\" as \"environment\", \"app_id\" as \"app_id\", \"user_agent\" as \"user_agent\", \"session_id\" as \"session_id\", \"created_at\" as \"created_at\", \"last_seen_at\" as \"last_seen_at\" from \"notifications\".\"devices\" where \"user_id\" = $1 order by \"last_seen_at\" desc","params":["b"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",2950],["user_id",25],["kind",25],["token",25],["p256dh",25],["auth",25],["environment",25],["app_id",25],["user_agent",25],["session_id",25],["created_at",1184],["last_seen_at",1184]],"rows":[["85de8598-8bad-4558-ab4e-11440901106c","b","web","https://fcm.googleapis.com/fcm/send/b-busy","BG_wO5SSQc4drdQ1GeaWDgqFtBppoFwygQOqK84VlMoWPE91OlW_AdxT9sCwx-7ni0DG_30lqW4igrmJzvccFEo","AgICAgICAgICAgICAgICAg",null,null,null,null,"2026-08-01 00:00:00+00","2026-08-01 00:00:00+00"]]}}, {"sql":"select 1 from \"jobs\".\"job\" where name = $1 and id = $2::uuid and state = 'active' and started_on > $3::timestamptz - interval '1 millisecond' and started_on < $4::timestamptz + interval '1 millisecond'","params":["notifications.send","{{uuid:1:4}}","{{now:2:T:3:+00:00}}","{{now:2:T:3:+00:00}}"],"result":{"command":"SELECT","rowCount":1,"columns":[["?column?",23]],"rows":[["1"]]}}, {"sql":"update \"jobs\".\"job\" set data = jsonb_set(data, '{progress}', $1::jsonb) where name = $2 and id = $3::uuid and state = 'active' and started_on > $4::timestamptz - interval '1 millisecond' and started_on < $5::timestamptz + interval '1 millisecond'","params":["{\"recorded\":[\"a\",\"b\",\"deleted\"],\"done\":[\"34db7c02-2036-444a-a4aa-01786fa52a08\",\"cc8fa173-065a-416c-b732-e5809f982be7\",\"85de8598-8bad-4558-ab4e-11440901106c\"],\"retried\":[\"85de8598-8bad-4558-ab4e-11440901106c\"]}","notifications.send","{{uuid:1:4}}","{{now:2:T:3:+00:00}}","{{now:2:T:3:+00:00}}"],"result":{"command":"UPDATE","rowCount":1,"columns":[],"rows":[]}}, {"sql":"select \"id\" as \"id\", \"user_id\" as \"user_id\", \"kind\" as \"kind\", \"token\" as \"token\", \"p256dh\" as \"p256dh\", \"auth\" as \"auth\", \"environment\" as \"environment\", \"app_id\" as \"app_id\", \"user_agent\" as \"user_agent\", \"session_id\" as \"session_id\", \"created_at\" as \"created_at\", \"last_seen_at\" as \"last_seen_at\" from \"notifications\".\"devices\" where \"user_id\" = $1 order by \"last_seen_at\" desc","params":["deleted"],"result":{"command":"SELECT","rowCount":0,"columns":[["id",2950],["user_id",25],["kind",25],["token",25],["p256dh",25],["auth",25],["environment",25],["app_id",25],["user_agent",25],["session_id",25],["created_at",1184],["last_seen_at",1184]],"rows":[]}}, {"sql":"update \"jobs\".\"job\" set data = $1::jsonb where name = $2 and id = $3::uuid and state = 'active' and started_on > $4::timestamptz - interval '1 millisecond' and started_on < $5::timestamptz + interval '1 millisecond'","params":["{\"complete\":true}","notifications.send","{{uuid:1:4}}","{{now:2:T:3:+00:00}}","{{now:2:T:3:+00:00}}"],"result":{"command":"UPDATE","rowCount":1,"columns":[],"rows":[]}}, {"sql":"select \"id\" as \"id\", \"user_id\" as \"user_id\", \"title\" as \"title\", \"body\" as \"body\", \"url\" as \"url\", \"data\" as \"data\", \"created_at\" as \"created_at\", \"read_at\" as \"read_at\" from \"notifications\".\"history\" where \"user_id\" = $1 \n order by \"created_at\" desc, \"id\" desc limit $2","params":["a","10"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",2950],["user_id",25],["title",25],["body",25],["url",25],["data",3802],["created_at",1184],["read_at",1184]],"rows":[["b91779b2-efc4-4300-bfad-6401c7b12c13","a","Update",null,"https://app.example/x",null,"2026-08-01 00:00:00+00",null]]}}, {"sql":"select \"id\" as \"id\", \"user_id\" as \"user_id\", \"title\" as \"title\", \"body\" as \"body\", \"url\" as \"url\", \"data\" as \"data\", \"created_at\" as \"created_at\", \"read_at\" as \"read_at\" from \"notifications\".\"history\" where \"user_id\" = $1 \n order by \"created_at\" desc, \"id\" desc limit $2","params":["b","10"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",2950],["user_id",25],["title",25],["body",25],["url",25],["data",3802],["created_at",1184],["read_at",1184]],"rows":[["13b8e51e-4228-4de4-b98d-17140371156b","b","Update",null,"https://app.example/x",null,"2026-08-01 00:00:00+00",null]]}}, {"sql":"select data from jobs.job where id = $1::uuid","params":["{{uuid:1:4}}"],"result":{"command":"SELECT","rowCount":1,"columns":[["data",3802]],"rows":[["{\"complete\": true}"]]}} ] }, "the send job on Postgres > records nothing and pushes nothing from a try that no longer holds its job": { "the send job on Postgres > records nothing and pushes nothing from a try that no longer holds its job#0": [ {"repeated":0}, {"sql":"create table people (id text primary key); insert into people values ('a'), ('b')","result":[{"command":"CREATE","rowCount":null,"columns":[],"rows":[]},{"command":"INSERT","rowCount":2,"columns":[],"rows":[]}]}, {"sql":"alter table notifications.history add foreign key (user_id) references people (id) on delete cascade","result":{"command":"ALTER","rowCount":null,"columns":[],"rows":[]}}, {"sql":"select jobs.enqueue($1, $2::jsonb) as id","params":["notifications.send","{\"to\":{\"userIds\":[\"a\"],\"inbox\":true},\"message\":{\"title\":\"Update\",\"url\":\"https://app.example/x\"}}"],"result":{"command":"SELECT","rowCount":1,"columns":[["id",2950]],"rows":[["{{uuid:2:4}}"]]}}, {"sql":"update jobs.job set state = 'active', started_on = now() + $1::interval, retry_count = $2 where id = $3::uuid returning data, started_on","params":["1 seconds","0","{{uuid:2:4}}"],"result":{"command":"UPDATE","rowCount":1,"columns":[["data",3802],["started_on",1184]],"rows":[["{\"to\": {\"inbox\": true, \"userIds\": [\"a\"]}, \"message\": {\"url\": \"https://app.example/x\", \"title\": \"Update\"}}","{{now:3: :-:+00}}"]]}}, {"sql":"update jobs.job set state = 'active', started_on = now() + $1::interval, retry_count = $2 where id = $3::uuid returning data, started_on","params":["2 seconds","1","{{uuid:2:4}}"],"result":{"command":"UPDATE","rowCount":1,"columns":[["data",3802],["started_on",1184]],"rows":[["{\"to\": {\"inbox\": true, \"userIds\": [\"a\"]}, \"message\": {\"url\": \"https://app.example/x\", \"title\": \"Update\"}}","{{now:4: :-:+00}}"]]}}, {"sql":"begin","result":{"command":"BEGIN","rowCount":null,"columns":[],"rows":[]}}, {"sql":"insert into \"notifications\".\"history\" (\"id\", \"user_id\", \"title\", \"body\", \"url\", \"data\", \"created_at\", \"read_at\") values ($1, $2, $3, $4, $5, $6::jsonb, $7, $8) returning \"id\" as \"id\", \"user_id\" as \"user_id\", \"title\" as \"title\", \"body\" as \"body\", \"url\" as \"url\", \"data\" as \"data\", \"created_at\" as \"created_at\", \"read_at\" as \"read_at\"","params":["adfcd1ef-74d5-4f68-a59c-b14f4449cae8","a","Update",null,"https://app.example/x",null,"2026-08-01T00:00:00.000+00:00",null],"result":{"command":"INSERT","rowCount":1,"columns":[["id",2950],["user_id",25],["title",25],["body",25],["url",25],["data",3802],["created_at",1184],["read_at",1184]],"rows":[["adfcd1ef-74d5-4f68-a59c-b14f4449cae8","a","Update",null,"https://app.example/x",null,"2026-08-01 00:00:00+00",null]]}}, {"sql":"update \"jobs\".\"job\" set data = jsonb_set(data, '{progress}', $1::jsonb) where name = $2 and id = $3::uuid and state = 'active' and started_on > $4::timestamptz - interval '1 millisecond' and started_on < $5::timestamptz + interval '1 millisecond'","params":["{\"recorded\":[\"a\"],\"done\":[],\"retried\":[]}","notifications.send","{{uuid:2:4}}","{{now:3:T:3:+00:00}}","{{now:3:T:3:+00:00}}"],"result":{"command":"UPDATE","rowCount":0,"columns":[],"rows":[]}}, {"sql":"rollback","result":{"command":"ROLLBACK","rowCount":null,"columns":[],"rows":[]}}, {"sql":"select \"id\" as \"id\", \"user_id\" as \"user_id\", \"title\" as \"title\", \"body\" as \"body\", \"url\" as \"url\", \"data\" as \"data\", \"created_at\" as \"created_at\", \"read_at\" as \"read_at\" from \"notifications\".\"history\" where \"user_id\" = $1 \n order by \"created_at\" desc, \"id\" desc limit $2","params":["a","10"],"result":{"command":"SELECT","rowCount":0,"columns":[["id",2950],["user_id",25],["title",25],["body",25],["url",25],["data",3802],["created_at",1184],["read_at",1184]],"rows":[]}} ] } }