/* 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;