Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
add db migration and set first team to trial plan
Marc Seitzc96c9bd5cb58
diff --git a/pages/api/teams/index.ts b/pages/api/teams/index.tsindex d76782d4..c39d8ee6 100644--- a/pages/api/teams/index.ts+++ b/pages/api/teams/index.ts@@ -47,6 +47,7 @@ export default async function handle(const defaultTeam = await prisma.team.create({data: {name: defaultTeamName,+ plan: "trial",users: {create: {userId: user.id,diff --git a/prisma/migrations/20231105152632_create_team/migration.sql b/prisma/migrations/20231105152632_create_team/migration.sqlnew file mode 100644index 00000000..a850bfde--- /dev/null+++ b/prisma/migrations/20231105152632_create_team/migration.sql@@ -0,0 +1,77 @@+-- CreateEnum+CREATE TYPE "Role" AS ENUM ('ADMIN', 'MEMBER');++-- AlterTable+ALTER TABLE "Document" ADD COLUMN "teamId" TEXT;++-- AlterTable+ALTER TABLE "Domain" ADD COLUMN "teamId" TEXT;++-- AlterTable+ALTER TABLE "User" ALTER COLUMN "plan" SET DEFAULT 'trial';++-- CreateTable+CREATE TABLE "Team" (+ "id" TEXT NOT NULL,+ "name" TEXT NOT NULL,+ "plan" TEXT NOT NULL DEFAULT 'free',+ "stripeId" TEXT,+ "subscriptionId" TEXT,+ "startsAt" TIMESTAMP(3),+ "endsAt" TIMESTAMP(3),+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,+ "updatedAt" TIMESTAMP(3) NOT NULL,++ CONSTRAINT "Team_pkey" PRIMARY KEY ("id")+);++-- CreateTable+CREATE TABLE "UserTeam" (+ "role" "Role" NOT NULL DEFAULT 'MEMBER',+ "userId" TEXT NOT NULL,+ "teamId" TEXT NOT NULL,++ CONSTRAINT "UserTeam_pkey" PRIMARY KEY ("userId","teamId")+);++-- CreateTable+CREATE TABLE "Invitation" (+ "email" TEXT NOT NULL,+ "expires" TIMESTAMP(3) NOT NULL,+ "teamId" TEXT NOT NULL,+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,+ "token" TEXT NOT NULL+);++-- CreateIndex+CREATE UNIQUE INDEX "Team_stripeId_key" ON "Team"("stripeId");++-- CreateIndex+CREATE UNIQUE INDEX "Team_subscriptionId_key" ON "Team"("subscriptionId");++-- CreateIndex+CREATE INDEX "UserTeam_userId_idx" ON "UserTeam"("userId");++-- CreateIndex+CREATE INDEX "UserTeam_teamId_idx" ON "UserTeam"("teamId");++-- CreateIndex+CREATE UNIQUE INDEX "Invitation_token_key" ON "Invitation"("token");++-- CreateIndex+CREATE UNIQUE INDEX "Invitation_email_key" ON "Invitation"("email");++-- AddForeignKey+ALTER TABLE "UserTeam" ADD CONSTRAINT "UserTeam_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;++-- AddForeignKey+ALTER TABLE "UserTeam" ADD CONSTRAINT "UserTeam_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;++-- AddForeignKey+ALTER TABLE "Document" ADD CONSTRAINT "Document_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE SET NULL ON UPDATE CASCADE;++-- AddForeignKey+ALTER TABLE "Domain" ADD CONSTRAINT "Domain_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE SET NULL ON UPDATE CASCADE;++-- AddForeignKey+ALTER TABLE "Invitation" ADD CONSTRAINT "Invitation_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 49cd1815..12e48e4d 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -105,7 +105,7 @@ model Document {numPages Int? // This should be a reference to the number of pages in the documentowner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)teamId String?- team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)+ team Team? @relation(fields: [teamId], references: [id], onDelete: SetNull)ownerId String // This field holds the foreign key.createdAt DateTime @default(now())updatedAt DateTime @updatedAt@@ -172,7 +172,7 @@ model Domain {user User @relation(fields: [userId], references: [id], onDelete: Cascade)userId StringteamId String?- Team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)+ Team Team? @relation(fields: [teamId], references: [id], onDelete: SetNull)verified Boolean @default(false) // Whether the domain has been verifiedlastChecked DateTime @default(now())createdAt DateTime @default(now())