-- Repair IruInquiry.offeringId when it incorrectly stores IruOffering.offeringId (business code)
-- instead of IruOffering.id (UUID). FK: IruInquiry.offeringId -> IruOffering.id
--
-- Review affected rows first:
--   SELECT i."inquiryId", i."offeringId" AS broken_fk, o.id AS correct_uuid, o."offeringId" AS business_id
--   FROM "IruInquiry" i
--   INNER JOIN "IruOffering" o ON o."offeringId" = i."offeringId"
--   WHERE i."offeringId" <> o.id;
--
-- Apply (transaction recommended):
--   BEGIN;
--   \i scripts/sql/fix-iru-inquiry-offering-fk.sql
--   COMMIT;

UPDATE "IruInquiry" AS i
SET "offeringId" = o.id
FROM "IruOffering" AS o
WHERE o."offeringId" = i."offeringId"
  AND i."offeringId" IS DISTINCT FROM o.id;
