Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Call gen_random_uuid directly from the public schema (#944)
Also fix 11.up -- otherwise users without public in their search path will not be able to install it. Likewise do nothing on 13.down -- so users downgrading will get to a version *with* the public prefix, just as they would with the _new_ 11.up.
- Loading branch information
1 parent
0f3084a
commit 24974e3
Showing
3 changed files
with
31 additions
and
1 deletion.
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
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,3 @@ | ||
-- Do nothing on DOWN. "UP" exists only to fix a bug in a function defined in | ||
-- 000011_parade.up.sql, which looks up `gen_random_uuid' with no schema. Now | ||
-- that version is gone, so always uses the schema. |
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,27 @@ | ||
-- Marks up to `max_tasks' on one of `actions' as in-progress and | ||
-- belonging to `actor_id' and returns their ids and a "performance | ||
-- token". Both must be returned to complete the task successfully. | ||
CREATE OR REPLACE FUNCTION own_tasks( | ||
max_tasks INTEGER, actions VARCHAR ARRAY, owner_id VARCHAR, max_duration INTERVAL | ||
) | ||
RETURNS TABLE(task_id VARCHAR, token UUID, num_failures INTEGER, action VARCHAR, body TEXT) | ||
LANGUAGE sql VOLATILE AS $$ | ||
UPDATE tasks | ||
SET actor_id = owner_id, | ||
status_code = 'in-progress', | ||
num_tries = num_tries + 1, | ||
performance_token = public.gen_random_uuid(), | ||
action_deadline = NOW() + max_duration -- NULL if max_duration IS NULL | ||
WHERE id IN ( | ||
SELECT id | ||
FROM tasks | ||
WHERE can_allocate_task(id, status_code, action_deadline, num_signals, total_dependencies) AND | ||
action = ANY(actions) AND | ||
(max_tries IS NULL OR num_tries < max_tries) | ||
-- maybe: AND not_before <= NOW() | ||
-- maybe: ORDER BY priority (eventually) | ||
ORDER BY random() | ||
FOR UPDATE SKIP LOCKED | ||
LIMIT max_tasks) | ||
RETURNING id, performance_token, num_failures, action, body | ||
$$; |