From a3b02d20ebf5eebfaf07b2d03d318fb8f0723eb2 Mon Sep 17 00:00:00 2001 From: piopi Date: Mon, 13 Jan 2025 09:13:46 -0500 Subject: [PATCH] feat: add tenant table/logic --- .../migration.sql | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 prisma/migrations/20250113141320_add_tenant_table/migration.sql diff --git a/prisma/migrations/20250113141320_add_tenant_table/migration.sql b/prisma/migrations/20250113141320_add_tenant_table/migration.sql new file mode 100644 index 0000000..3634aa2 --- /dev/null +++ b/prisma/migrations/20250113141320_add_tenant_table/migration.sql @@ -0,0 +1,39 @@ +/* + Warnings: + + - The primary key for the `User` table will be changed. If it partially fails, the table could be left without primary key constraint. + - A unique constraint covering the columns `[clerkId,tenantId]` on the table `User` will be added. If there are existing duplicate values, this will fail. + - Added the required column `tenantId` to the `User` table without a default value. This is not possible if the table is not empty. + +*/ +-- DropIndex +DROP INDEX "User_clerkId_key"; + +-- AlterTable +ALTER TABLE "User" DROP CONSTRAINT "User_pkey", +ADD COLUMN "tenantId" TEXT NOT NULL, +ADD CONSTRAINT "User_pkey" PRIMARY KEY ("id", "tenantId"); + +-- CreateTable +CREATE TABLE "tenant" ( + "id" TEXT NOT NULL, + "name" TEXT NOT NULL, + "slug" TEXT NOT NULL, + "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updated_at" TIMESTAMP(3) NOT NULL, + "clerkId" TEXT NOT NULL, + + CONSTRAINT "tenant_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "tenant_slug_key" ON "tenant"("slug"); + +-- CreateIndex +CREATE UNIQUE INDEX "tenant_clerkId_key" ON "tenant"("clerkId"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_clerkId_tenantId_key" ON "User"("clerkId", "tenantId"); + +-- AddForeignKey +ALTER TABLE "User" ADD CONSTRAINT "User_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "tenant"("id") ON DELETE RESTRICT ON UPDATE CASCADE;