39 lines
1.4 KiB
SQL
39 lines
1.4 KiB
SQL
/*
|
|
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,
|
|
"clerkOrganizationId" TEXT NOT NULL,
|
|
|
|
CONSTRAINT "Tenant_pkey" PRIMARY KEY ("id")
|
|
);
|
|
|
|
-- CreateIndex
|
|
CREATE UNIQUE INDEX "Tenant_slug_key" ON "Tenant"("slug");
|
|
|
|
-- CreateIndex
|
|
CREATE UNIQUE INDEX "Tenant_clerkOrganizationId_key" ON "Tenant"("clerkOrganizationId");
|
|
|
|
-- 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;
|