-- CreateTable
CREATE TABLE "tbl_payment_history" (
    "id" BIGSERIAL NOT NULL,
    "user_id" BIGINT NOT NULL,
    "brand_id" BIGINT NOT NULL,
    "order_id" BIGINT NOT NULL,
    "customer_id" VARCHAR(128),
    "payment_intent_id" VARCHAR(256),
    "payment_method" VARCHAR(256),
    "paid_amount" DECIMAL(13,2),
    "status" VARCHAR(128),
    "currency" VARCHAR(64),
    "payment_intent_log" TEXT,
    "inserted_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3),

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

-- CreateIndex
CREATE INDEX "tbl_payment_history_user_id_idx" ON "tbl_payment_history"("user_id");

-- CreateIndex
CREATE INDEX "tbl_payment_history_brand_id_idx" ON "tbl_payment_history"("brand_id");

-- CreateIndex
CREATE INDEX "tbl_payment_history_order_id_idx" ON "tbl_payment_history"("order_id");

-- CreateIndex
CREATE INDEX "tbl_payment_history_customer_id_idx" ON "tbl_payment_history"("customer_id");

-- CreateIndex
CREATE INDEX "tbl_payment_history_payment_intent_id_idx" ON "tbl_payment_history"("payment_intent_id");

-- CreateIndex
CREATE INDEX "tbl_payment_history_payment_method_idx" ON "tbl_payment_history"("payment_method");

-- CreateIndex
CREATE INDEX "tbl_payment_history_paid_amount_idx" ON "tbl_payment_history"("paid_amount");

-- CreateIndex
CREATE INDEX "tbl_payment_history_status_idx" ON "tbl_payment_history"("status");

-- CreateIndex
CREATE INDEX "tbl_payment_history_currency_idx" ON "tbl_payment_history"("currency");

-- AddForeignKey
ALTER TABLE "tbl_payment_history" ADD CONSTRAINT "tbl_payment_history_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "tbl_user"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tbl_payment_history" ADD CONSTRAINT "tbl_payment_history_brand_id_fkey" FOREIGN KEY ("brand_id") REFERENCES "tbl_user"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tbl_payment_history" ADD CONSTRAINT "tbl_payment_history_order_id_fkey" FOREIGN KEY ("order_id") REFERENCES "tbl_order"("id") ON DELETE CASCADE ON UPDATE CASCADE;
