ALTER TABLE akuz.t_inability
ADD COLUMN post INTEGER;

UPDATE akuz.t_inability i
SET post = mr.post
FROM akuz.t_medical_record mr
WHERE mr.medicalrecordid = i.medicalrecordid;

ALTER TABLE akuz.t_inability
DROP CONSTRAINT fk_t_inability_t_medical_record;

DELETE FROM akuz.t_medical_record mr
USING akuz.t_inability cte
WHERE mr.medicalrecordid = cte.medicalrecordid;

ALTER TABLE akuz.t_inability
ADD CONSTRAINT fk_t_post_t_inability_post
FOREIGN KEY (post) REFERENCES akuz.t_post (resourceid);

ALTER TABLE akuz.t_inability
ALTER COLUMN post SET NOT NULL;
