Files
archie/internal/infrastructure/postgres/migrations/0045_chat_issue_numbers.sql
T
sam 32cd65a58a fix(postgres): allocate synthetic issue numbers from a per-repo counter
InsertChatTask and EnqueueCallTask computed MAX(issue_number)+1, so
concurrent inserts in one repository took the same number and the second
failed on the unique key. Both now bump a chat_issue_numbers row, seeded
from the existing maxima, whose row lock serializes allocation.
2026-10-11 14:21:27 +00:00

20 lines
649 B
SQL

-- 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;