-- Add reviewToken to reservations for secure one-time review links
ALTER TABLE "reservations" ADD COLUMN "reviewToken" TEXT;
CREATE UNIQUE INDEX "reservations_reviewToken_key" ON "reservations"("reviewToken");

-- Make renterId optional on reviews (reviews can come from non-Carplace customers via token link)
ALTER TABLE "reviews" ALTER COLUMN "renterId" DROP NOT NULL;
ALTER TABLE "reviews" DROP CONSTRAINT IF EXISTS "reviews_renterId_fkey";
ALTER TABLE "reviews" ADD CONSTRAINT "reviews_renterId_fkey"
  FOREIGN KEY ("renterId") REFERENCES "renters"("id") ON DELETE SET NULL ON UPDATE CASCADE;
