-- CreateEnum
CREATE TYPE "MerchantUserRole" AS ENUM ('ADMIN', 'MANAGER', 'TECHNICAL', 'VIEWER');

-- CreateTable
CREATE TABLE "merchant_users" (
    "id" SERIAL NOT NULL,
    "userId" TEXT NOT NULL,
    "merchantPartnerId" INTEGER NOT NULL,
    "role" "MerchantUserRole" NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "merchant_users_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "merchant_users_userId_merchantPartnerId_key" ON "merchant_users"("userId", "merchantPartnerId");

-- AddForeignKey
ALTER TABLE "merchant_users" ADD CONSTRAINT "merchant_users_merchantPartnerId_fkey" FOREIGN KEY ("merchantPartnerId") REFERENCES "merchant_partners"("id") ON DELETE CASCADE ON UPDATE CASCADE;
