g1t/services/deployments/migrations/0006_replaced_and_down.sql
| 1 | -- A build stays 'ready' only while it is what its app serves. One a newer |
| 2 | -- build replaced becomes 'replaced'; one whose app was taken down becomes |
| 3 | -- 'down'. This corrects the builds already recorded. |
| 4 | |
| 5 | -- Taken down: no app holds the script any more. |
| 6 | UPDATE deployments SET status = 'down' |
| 7 | WHERE status = 'ready' AND script NOT IN (SELECT script FROM apps); |
| 8 | |
| 9 | -- Replaced: a later ready build of the same app exists. |
| 10 | UPDATE deployments SET status = 'replaced' |
| 11 | WHERE status = 'ready' |
| 12 | AND EXISTS ( |
| 13 | SELECT 1 FROM deployments newer |
| 14 | WHERE newer.script = deployments.script AND newer.status = 'ready' |
| 15 | AND COALESCE(newer.finished_at, newer.created_at) > COALESCE(deployments.finished_at, deployments.created_at) |
| 16 | ); |