-- Enforce the business rules at the database level:
--   1. A meeting summary must always belong to a meeting (meeting_id NOT NULL).
--   2. One meeting can have only one meeting summary (unique meeting_id).
-- The table is empty at the time of writing, so no backfill is needed.

-- Rule 1: every summary must point to a meeting.
ALTER TABLE "meeting_summaries" ALTER COLUMN "meeting_id" SET NOT NULL;

-- Rule 2: replace the plain index with a unique one (one summary per meeting).
DROP INDEX "meeting_summaries_meeting_id_idx";
CREATE UNIQUE INDEX "meeting_summaries_meeting_id_key" ON "meeting_summaries"("meeting_id");

-- The old foreign key used ON DELETE SET NULL, which cannot work on a NOT NULL
-- column. Recreate it with RESTRICT (Prisma's default for a required relation).
ALTER TABLE "meeting_summaries" DROP CONSTRAINT "meeting_summaries_meeting_id_fkey";
ALTER TABLE "meeting_summaries" ADD CONSTRAINT "meeting_summaries_meeting_id_fkey"
  FOREIGN KEY ("meeting_id") REFERENCES "meetings"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
