-- AlterTable
ALTER TABLE "Patient"
ADD COLUMN     "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN     "creatorId" INTEGER;

-- Backfill
UPDATE "Patient"
SET "creatorId" = "doctorId"
WHERE "creatorId" IS NULL;

-- AlterTable
ALTER TABLE "Patient"
ALTER COLUMN "creatorId" SET NOT NULL;

-- CreateIndex
CREATE INDEX "Patient_creatorId_idx" ON "Patient"("creatorId");

-- AddForeignKey
ALTER TABLE "Patient" ADD CONSTRAINT "Patient_creatorId_fkey" FOREIGN KEY ("creatorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
