-- chat_issue_numbers holds the last synthetic issue number allocated in each -- repository. Chat and workflow.call tasks take theirs by bumping this row, -- whose row lock serializes concurrent inserts in one repository, which a -- MAX(issue_number) read under READ COMMITTED cannot. -- +goose Up CREATE TABLE chat_issue_numbers ( owner text NOT NULL, repo text NOT NULL, last_number bigint NOT NULL, PRIMARY KEY (owner, repo) ); INSERT INTO chat_issue_numbers (owner, repo, last_number) SELECT owner, repo, MAX(issue_number) FROM tasks WHERE source = 'chat' GROUP BY owner, repo; -- +goose Down DROP TABLE chat_issue_numbers;