| 1 | alter table jobs |
| 2 | add column attempts integer not null default 0, |
| 3 | add column run_at timestamptz not null default now(), |
| 4 | add column claimed_at timestamptz, |
| 5 | add column last_error text; |
| 6 | |
| 7 | alter table jobs |
| 8 | drop constraint jobs_status_check, |
| 9 | add constraint jobs_status_check check (status in ('waiting', 'running', 'dead')); |
| 10 | |
| 11 | -- A job that is running right now was claimed now, as far as we know. |
| 12 | update jobs set claimed_at = now() where status = 'running'; |
| 13 | |
| 14 | create index jobs_run_at_id_idx on jobs (run_at, id) where status = 'waiting'; |