| 1 | -- Each workspace's floor: the highest number any of its repositories used |
| 2 | -- on its own before work items moved to the workspace (a pull request |
| 3 | -- opened by then, or an old issue's number). Numbers above it are the |
| 4 | -- workspace's alone; at or below it, `#N` read in the workspace may be any |
| 5 | -- of its repositories' old pull requests, so it names none of them from |
| 6 | -- elsewhere (items/refs.rs). The job sets it from here on |
| 7 | -- (items/migration.rs `place_sql`); this sets it for workspaces that moved |
| 8 | -- before, as `RAISE_FLOORS` does. |
| 9 | ALTER TABLE work_counters ADD COLUMN floor INTEGER NOT NULL DEFAULT 0; |
| 10 | |
| 11 | UPDATE work_counters SET floor = MAX(floor, |
| 12 | COALESCE((SELECT MAX(p.number) FROM pulls p JOIN repo_workspaces rw ON rw.repo_id = p.repo_id |
| 13 | WHERE rw.workspace = work_counters.workspace |
| 14 | AND p.created_at <= COALESCE((SELECT done_at FROM work_jobs WHERE name = 'work_items'), '')), 0), |
| 15 | COALESCE((SELECT MAX(l.legacy_number) FROM work_item_repos l JOIN repo_workspaces rw ON rw.repo_id = l.repo_id |
| 16 | WHERE rw.workspace = work_counters.workspace), 0)) |
| 17 | WHERE true; |
| 18 | |
| 19 | -- The job that records the repositories the first left out: deleted, but |
| 20 | -- still restorable, when it ran. Their work items were placed in their |
| 21 | -- workspace with no path, as private, with their labels and old numbers |
| 22 | -- unmerged (items/migration.rs `migrate_deleted_repos`). It runs once the |
| 23 | -- first is done, and again changes nothing. |
| 24 | INSERT INTO work_jobs (name) VALUES ('deleted_repos'); |