ALTER TABLE computer_jobs ADD COLUMN IF NOT EXISTS run_id TEXT REFERENCES runs(id) ON DELETE SET NULL; -- A local sequence belongs to one provisioned Computer generation. CREATE TABLE computer_job_events ( computer_id TEXT NOT NULL REFERENCES computers(id) ON DELETE CASCADE, generation INTEGER NOT NULL, provider_ref TEXT NOT NULL, local_id BIGINT NOT NULL, job_id TEXT NOT NULL, event TEXT NOT NULL, payload JSONB NOT NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT now(), PRIMARY KEY (computer_id, generation, provider_ref, local_id) ); CREATE INDEX computer_job_events_retention ON computer_job_events(created_at);