-- CreateTable
CREATE TABLE "plans" (
    "code" VARCHAR(10) NOT NULL,
    "name" VARCHAR(30) NOT NULL,
    "price" DECIMAL(19,2) NOT NULL,
    "rules" JSONB NOT NULL,
    "last_updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "plans_pkey" PRIMARY KEY ("code")
);

-- CreateTable
CREATE TABLE "complexes" (
    "id" UUID NOT NULL,
    "complex_name" TEXT NOT NULL,
    "complex_slug" TEXT NOT NULL,
    "admin_email" TEXT NOT NULL,
    "plan_code" VARCHAR(10),
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "complexes_complex_slug_key" ON "complexes"("complex_slug");

-- CreateIndex
CREATE INDEX "complexes_plan_code_idx" ON "complexes"("plan_code");

-- AddForeignKey
ALTER TABLE "complexes" ADD CONSTRAINT "complexes_plan_code_fkey" FOREIGN KEY ("plan_code") REFERENCES "plans"("code") ON DELETE SET NULL ON UPDATE CASCADE;
