-- verification_logs.verification_request_id was mistakenly created (init-db.sql)
-- referencing the legacy, unrelated verification_requests table instead of the
-- verifications table it actually logs against. VerificationRepository::update_status
-- inserts the verifications.id into this column on every approve/reject/status-change
-- call, which has been violating the foreign key constraint on every single call
-- ("insert or update on table verification_logs violates foreign key constraint
-- verification_logs_verification_request_id_fkey"), making Approve/Reject 500 every time.

BEGIN;

ALTER TABLE verification_logs DROP CONSTRAINT IF EXISTS verification_logs_verification_request_id_fkey;
ALTER TABLE verification_logs
    ADD CONSTRAINT verification_logs_verification_request_id_fkey
    FOREIGN KEY (verification_request_id) REFERENCES verifications(id) ON DELETE CASCADE;

COMMIT;
