| 1 | -- Issues became work items (g1t #57). What needs only names is rewritten |
| 2 | -- here; what was kept by a repository's issue number (inbox threads, |
| 3 | -- subscriptions, the log's events) is rewritten as the work service |
| 4 | -- announces where each issue went (`work.migrated`, src/work_items.rs), |
| 5 | -- recorded in `work_migrated`. |
| 6 | |
| 7 | -- Inbox items about an issue are about its work item. |
| 8 | UPDATE inbox_items SET subject = 'item' WHERE subject = 'issue'; |
| 9 | |
| 10 | -- A custom watch that followed issues follows work items. |
| 11 | UPDATE inbox_watching |
| 12 | SET events = ( |
| 13 | SELECT json_group_array(CASE value WHEN 'issues' THEN 'work_items' ELSE value END) |
| 14 | FROM json_each(inbox_watching.events) |
| 15 | ) |
| 16 | WHERE EXISTS (SELECT 1 FROM json_each(inbox_watching.events) WHERE value = 'issues'); |
| 17 | |
| 18 | -- Subscriptions to a work item keep its origin as `repo_id`, and one |
| 19 | -- with no origin has none. |
| 20 | CREATE TABLE inbox_subscriptions_new ( |
| 21 | username TEXT NOT NULL, |
| 22 | -- `<repo_id>#<number>` for a pull request, `item:<item_id>` for a work item. |
| 23 | thread TEXT NOT NULL, |
| 24 | -- The pull request's repository, or the work item's origin. |
| 25 | repo_id TEXT, |
| 26 | -- subscribed | unsubscribed | ignored |
| 27 | state TEXT NOT NULL, |
| 28 | -- Why: comment, mention, assign, review_requested, author or manual. |
| 29 | reason TEXT, |
| 30 | created_at TEXT NOT NULL, |
| 31 | -- When the person last chose (subscribed, unsubscribed or ignored by |
| 32 | -- hand); null while it only follows what they did. |
| 33 | chosen_at TEXT, |
| 34 | PRIMARY KEY (thread, username) |
| 35 | ); |
| 36 | INSERT INTO inbox_subscriptions_new (username, thread, repo_id, state, reason, created_at, chosen_at) |
| 37 | SELECT username, thread, repo_id, state, reason, created_at, chosen_at FROM inbox_subscriptions; |
| 38 | DROP TABLE inbox_subscriptions; |
| 39 | ALTER TABLE inbox_subscriptions_new RENAME TO inbox_subscriptions; |
| 40 | CREATE INDEX inbox_subscriptions_repo ON inbox_subscriptions (repo_id); |
| 41 | |
| 42 | -- Where each repository's issues went, a page of `work.migrated` at a time. |
| 43 | CREATE TABLE work_migrated ( |
| 44 | repo_id TEXT NOT NULL, |
| 45 | -- The issue's number in its repository. |
| 46 | legacy_number INTEGER NOT NULL, |
| 47 | -- The work item's workspace (a slug), number in it, and id. |
| 48 | workspace TEXT NOT NULL, |
| 49 | number INTEGER NOT NULL, |
| 50 | item_id TEXT NOT NULL, |
| 51 | -- The `work.migrated` event that said so. |
| 52 | event_id TEXT NOT NULL, |
| 53 | PRIMARY KEY (repo_id, legacy_number) |
| 54 | ); |
| 55 | CREATE INDEX work_migrated_event ON work_migrated (event_id); |