ALTER TABLE projects
    ADD COLUMN eta_interval_seconds integer;

UPDATE projects
SET eta_interval_seconds = CASE
    WHEN eta_mode = 'CONTINUOUS' THEN GREATEST(1, ROUND(60 / continuous_rate_per_minute)::integer)
    ELSE GREATEST(1, ROUND(average_batch_interval_seconds::numeric / call_batch_size)::integer)
END;

ALTER TABLE projects
    ALTER COLUMN eta_interval_seconds SET DEFAULT 60,
    ALTER COLUMN eta_interval_seconds SET NOT NULL,
    ADD CONSTRAINT projects_eta_interval_check CHECK (eta_interval_seconds BETWEEN 1 AND 86400);
