flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/services/deployments/migrations/0006_replaced_and_down.sql

16 lines728 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Builds say Replaced or Down once they are no longer live1-- 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.
6UPDATE deployments SET status = 'down'
7WHERE status = 'ready' AND script NOT IN (SELECT script FROM apps);
8
9-- Replaced: a later ready build of the same app exists.
10UPDATE deployments SET status = 'replaced'
11WHERE 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 );