-- Migration: Create favorite_jobs table
-- Description: Users can save favorite jobs for later

CREATE TABLE IF NOT EXISTS favorite_jobs (
    id SERIAL PRIMARY KEY,
    user_id INT NOT NULL,
    job_id INT NOT NULL,
    
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    
    -- Foreign keys
    FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
    FOREIGN KEY (job_id) REFERENCES jobs(id) ON DELETE CASCADE,
    
    -- Ensure user can't favorite same job twice
    UNIQUE(user_id, job_id)
);

-- Indexes
CREATE INDEX idx_favorite_jobs_user ON favorite_jobs(user_id);
CREATE INDEX idx_favorite_jobs_job ON favorite_jobs(job_id);

-- Comments
COMMENT ON TABLE favorite_jobs IS 'Saved/favorited jobs by users';
