-- CreateTable CREATE TABLE "PlanShare" ( "id" TEXT NOT NULL, "planId" TEXT NOT NULL, "sharedById" TEXT NOT NULL, "sharedWithId" TEXT NOT NULL, "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT "PlanShare_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE INDEX "PlanShare_sharedWithId_idx" ON "PlanShare"("sharedWithId"); -- CreateIndex CREATE UNIQUE INDEX "PlanShare_planId_sharedWithId_key" ON "PlanShare"("planId", "sharedWithId"); -- AddForeignKey ALTER TABLE "PlanShare" ADD CONSTRAINT "PlanShare_planId_fkey" FOREIGN KEY ("planId") REFERENCES "TrainingPlan"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "PlanShare" ADD CONSTRAINT "PlanShare_sharedById_fkey" FOREIGN KEY ("sharedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "PlanShare" ADD CONSTRAINT "PlanShare_sharedWithId_fkey" FOREIGN KEY ("sharedWithId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;