-- Part 8: operations query pack
-- Compose after: content/series/durable-work-postgres/source/schema.sql.
-- The post download links to ../../source/schema.sql for the full migration.

SELECT status, count(*)::int AS count
FROM inbox
GROUP BY status
ORDER BY status;

SELECT id, partition_key, now() - created_at AS age
FROM inbox
WHERE status = 'pending'
ORDER BY created_at, id
LIMIT 20;

SELECT id, partition_key, claimed_by, lease_expires_at, attempts, last_error
FROM inbox
WHERE status = 'processing'
  AND lease_expires_at < now()
ORDER BY lease_expires_at, id
LIMIT 50;
