circus/crates/common/migrations/014_fix_build_stats_completed.sql
NotAShelf 541cd7832f
treewide: replace BuildStatus::Completed with BuildStatus::Succeeded
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I965dfaca211f9fde527a84a54ae972576a6a6964
2026-02-16 23:42:21 +03:00

17 lines
776 B
SQL

-- Fix build_stats view and data after 'completed' -> 'succeeded' status rename
-- Migrate any existing builds still using the old status value
UPDATE builds SET status = 'succeeded' WHERE status = 'completed';
-- Recreate the build_stats view to reference the new status
DROP VIEW IF EXISTS build_stats;
CREATE VIEW build_stats AS
SELECT
COUNT(*) as total_builds,
COUNT(CASE WHEN status = 'succeeded' THEN 1 END) as completed_builds,
COUNT(CASE WHEN status = 'failed' THEN 1 END) as failed_builds,
COUNT(CASE WHEN status = 'running' THEN 1 END) as running_builds,
COUNT(CASE WHEN status = 'pending' THEN 1 END) as pending_builds,
AVG(EXTRACT(EPOCH FROM (completed_at - started_at))) as avg_duration_seconds
FROM builds
WHERE started_at IS NOT NULL;