-- Migration: Add date_posted to jobs
-- Description: Supports explicit posting date field consumed by frontend filters/sorting.

ALTER TABLE jobs
    ADD COLUMN IF NOT EXISTS date_posted TIMESTAMP WITH TIME ZONE;

UPDATE jobs
SET date_posted = created_at
WHERE date_posted IS NULL;

ALTER TABLE jobs
    ALTER COLUMN date_posted SET DEFAULT NOW();

CREATE INDEX IF NOT EXISTS idx_jobs_date_posted ON jobs(date_posted DESC);

COMMENT ON COLUMN jobs.date_posted IS 'Public posting timestamp used by listing/filtering UX';
