CREATE TABLE survey_jobs (
    id INT AUTO_INCREMENT PRIMARY KEY,
    settlement_id INT NOT NULL,
    survey_import_id INT NOT NULL,
    status ENUM('pending', 'processing', 'completed', 'failed') NOT NULL DEFAULT 'pending',
    error_message TEXT NULL,
    started_at DATETIME NULL,
    completed_at DATETIME NULL,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_survey_jobs_settlement (settlement_id),
    INDEX idx_survey_jobs_status (status),
    CONSTRAINT fk_survey_jobs_settlement FOREIGN KEY (settlement_id) REFERENCES settlements(id),
    CONSTRAINT fk_survey_jobs_import FOREIGN KEY (survey_import_id) REFERENCES survey_imports(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
