-- CreateTable CREATE TABLE "Note" ( "id" TEXT NOT NULL, "organizationId" TEXT NOT NULL, "title" TEXT, "body" TEXT NOT NULL, "pinned" BOOLEAN NOT NULL DEFAULT false, "color" TEXT DEFAULT 'default', "tags" TEXT[] DEFAULT ARRAY[]::TEXT[], "reminderAt" TIMESTAMP(3), "personId" TEXT, "companyId" TEXT, "dealId" TEXT, "authorId" TEXT, "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP(3) NOT NULL, CONSTRAINT "Note_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE INDEX "Note_organizationId_pinned_updatedAt_idx" ON "Note"("organizationId", "pinned", "updatedAt"); -- CreateIndex CREATE INDEX "Note_organizationId_reminderAt_idx" ON "Note"("organizationId", "reminderAt"); -- CreateIndex CREATE INDEX "Note_personId_idx" ON "Note"("personId"); -- CreateIndex CREATE INDEX "Note_companyId_idx" ON "Note"("companyId"); -- CreateIndex CREATE INDEX "Note_dealId_idx" ON "Note"("dealId"); -- CreateIndex CREATE INDEX "Note_authorId_idx" ON "Note"("authorId"); -- AddForeignKey ALTER TABLE "Note" ADD CONSTRAINT "Note_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Note" ADD CONSTRAINT "Note_personId_fkey" FOREIGN KEY ("personId") REFERENCES "Person"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Note" ADD CONSTRAINT "Note_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "Company"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Note" ADD CONSTRAINT "Note_dealId_fkey" FOREIGN KEY ("dealId") REFERENCES "Deal"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Note" ADD CONSTRAINT "Note_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;