ALTER TABLE AKUZ.T_CARD_NOTE_SIGNATURE ADD "cardnotefile" uuid NULL;

update AKUZ.T_CARD_NOTE_SIGNATURE
set CardNoteFile = (select FileID from AKUZ.T_CARD_NOTE_FILE cnf where cnf.CardNote = cn.MedicalRecordID limit 1)
from AKUZ.T_CARD_NOTE_SIGNATURE cns join AKUZ.T_CARD_NOTE cn on cn.MedicalRecordID = cns.CardNote;

ALTER TABLE AKUZ.T_CARD_NOTE_SIGNATURE ALTER COLUMN "cardnotefile" SET NOT NULL;

ALTER TABLE AKUZ.T_CARD_NOTE_SIGNATURE ADD CONSTRAINT FK_T_CARD_NOTE_FILE_T_CARD_NOTE_SIGNATURE_CardNoteFile
FOREIGN KEY("cardnotefile") REFERENCES AKUZ.T_CARD_NOTE_FILE (FileID);

ALTER TABLE AKUZ.T_CARD_NOTE_SIGNATURE DROP CONSTRAINT FK_T_CARD_NOTE_T_CARD_NOTE_SIGNATURE_CardNote;

ALTER TABLE AKUZ.T_CARD_NOTE_SIGNATURE DROP COLUMN "cardnote";