-- @AutoRun

UPDATE tl_answer AS an 
SET candidate_id = ja.candidate_id 
FROM tl_job_application AS ja 
WHERE an.job_application_id = ja.object_id;

UPDATE tl_culture_criteria_answer AS ca 
SET candidate_id = ja.candidate_id 
FROM tl_job_application AS ja 
WHERE ca.job_application_id =  ja.object_id;

UPDATE tl_culture_criteria_answer AS ca 
SET culture_element_id = cc.culture_element_id 
FROM tl_culture_criteria AS cc 
WHERE ca.culture_criteria_id =  cc.object_id;


ALTER TABLE tl_answer ALTER COLUMN candidate_id SET NOT NULL;

ALTER TABLE tl_culture_criteria_answer ALTER COLUMN candidate_id SET NOT NULL;

ALTER TABLE tl_culture_criteria_answer ALTER COLUMN culture_element_id SET NOT NULL;


DROP INDEX idx_tl_culture_criteria_answer_job_application_id;


ALTER TABLE tl_answer DROP COLUMN job_application_id;

ALTER TABLE tl_culture_criteria_answer DROP COLUMN job_application_id;

ALTER TABLE tl_culture_criteria_answer DROP COLUMN culture_criteria_id;
