internal/store/migrations/0067_merge_queue.up.sql

v1.41.0
gitbay/internal/store/migrations/0067_merge_queue.up.sql history · blame · raw

25 lines · 1312 bytes

 1-- A merge request queued with `mr merge --when-ready`: merged as user_id
 2-- with strategy once its gates pass. reason is why the last attempt did
 3-- not merge. A merge request that is merged or closed leaves the queue,
 4-- whichever path did it.
 5--
 6-- credential is what the merge was queued with: 'key' (key_id) or
 7-- 'token' (token_id), or '' for a web session, which binds to the
 8-- account alone. A removed key or revoked token nulls its id, so the id
 9-- of a later credential never stands in for it.
10CREATE TABLE mr_merge_queue (
11    mr_id      INTEGER PRIMARY KEY REFERENCES merge_requests(id) ON DELETE CASCADE,
12    user_id    INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
13    strategy   TEXT NOT NULL DEFAULT '',
14    credential TEXT NOT NULL DEFAULT '' CHECK (credential IN ('', 'key', 'token')),
15    key_id     INTEGER REFERENCES ssh_keys(id) ON DELETE SET NULL,
16    token_id   INTEGER REFERENCES api_tokens(id) ON DELETE SET NULL,
17    reason     TEXT NOT NULL DEFAULT '',
18    queued_at  TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
19);
20CREATE INDEX mr_merge_queue_user ON mr_merge_queue(user_id);
21CREATE TRIGGER mr_merge_queue_leave AFTER UPDATE OF state ON merge_requests
22WHEN NEW.state IN ('merged', 'closed')
23BEGIN
24    DELETE FROM mr_merge_queue WHERE mr_id = NEW.id;
25END;