-- CreateTable
CREATE TABLE IF NOT EXISTS "branch_units" (
    "id" TEXT NOT NULL,
    "branchId" TEXT NOT NULL,
    "unitId" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX IF NOT EXISTS "branch_units_branchId_unitId_key" ON "branch_units"("branchId", "unitId");

-- CreateIndex
CREATE INDEX IF NOT EXISTS "branch_units_branchId_idx" ON "branch_units"("branchId");

-- CreateIndex
CREATE INDEX IF NOT EXISTS "branch_units_unitId_idx" ON "branch_units"("unitId");

-- AddForeignKey
ALTER TABLE "branch_units" ADD CONSTRAINT "branch_units_branchId_fkey" FOREIGN KEY ("branchId") REFERENCES "branches"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "branch_units" ADD CONSTRAINT "branch_units_unitId_fkey" FOREIGN KEY ("unitId") REFERENCES "units"("id") ON DELETE CASCADE ON UPDATE CASCADE;
