Files
next-tjwater-server/resources/sql/027_calculation_job_lifecycle.sql
T
jiang 05183aff93
Generic Container CI/CD / test-build-publish (push) Successful in 3m53s
Server CI/CD v2 / build-test-publish-and-deploy (push) Successful in 3m52s
feat: extend operational investigation workflows
2026-10-30 17:30:19 +08:00

22 lines
1.3 KiB
SQL

-- Apply after 026, independently to every project business database.
-- Preserve job identity, deduplication and audit metadata, including legacy results.
ALTER TABLE workbench.calculation_jobs
ADD COLUMN IF NOT EXISTS started_at timestamptz,
ADD COLUMN IF NOT EXISTS finished_at timestamptz,
ADD COLUMN IF NOT EXISTS queue_expires_at timestamptz,
ADD COLUMN IF NOT EXISTS result_expires_at timestamptz;
UPDATE workbench.calculation_jobs SET queue_expires_at=created_at+interval '1 hour'
WHERE queue_expires_at IS NULL;
UPDATE workbench.calculation_jobs SET finished_at=updated_at
WHERE finished_at IS NULL AND status IN ('succeeded','failed','cancelled','timed_out','interrupted');
-- Give pre-deployment results a complete retention window, even on reruns.
UPDATE workbench.calculation_jobs SET result_expires_at=clock_timestamp()+interval '7 days'
WHERE result IS NOT NULL AND result_expires_at IS NULL;
ALTER TABLE workbench.calculation_jobs
ALTER COLUMN queue_expires_at SET DEFAULT (clock_timestamp()+interval '1 hour'),
ALTER COLUMN queue_expires_at SET NOT NULL;
CREATE INDEX IF NOT EXISTS calculation_jobs_queue_expiry
ON workbench.calculation_jobs(project_id,queue_expires_at) WHERE status='queued';
CREATE INDEX IF NOT EXISTS calculation_jobs_result_expiry
ON workbench.calculation_jobs(project_id,result_expires_at) WHERE result IS NOT NULL;