-- CreateTable: 批量补发执行记录（全局只允许执行一次）
CREATE TABLE "batch_mining_executions" (
    "id" TEXT NOT NULL,
    "operator_id" TEXT NOT NULL,
    "operator_name" TEXT NOT NULL,
    "reason" TEXT NOT NULL,
    "total_users" INTEGER NOT NULL,
    "total_batches" INTEGER NOT NULL,
    "success_count" INTEGER NOT NULL DEFAULT 0,
    "failed_count" INTEGER NOT NULL DEFAULT 0,
    "total_amount" DECIMAL(30,8) NOT NULL DEFAULT 0,
    "executed_at" TIMESTAMP(3) NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable: 批量补发明细记录
CREATE TABLE "batch_mining_records" (
    "id" TEXT NOT NULL,
    "execution_id" TEXT NOT NULL,
    "account_sequence" TEXT NOT NULL,
    "batch" INTEGER NOT NULL,
    "tree_count" INTEGER NOT NULL,
    "pre_mine_days" INTEGER NOT NULL,
    "user_contribution" DECIMAL(30,10) NOT NULL,
    "network_contribution" DECIMAL(30,10) NOT NULL,
    "contribution_ratio" DECIMAL(30,18) NOT NULL,
    "total_seconds" BIGINT NOT NULL,
    "amount" DECIMAL(30,8) NOT NULL,
    "remark" TEXT,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE UNIQUE INDEX "batch_mining_records_execution_id_account_sequence_key" ON "batch_mining_records"("execution_id", "account_sequence");

-- CreateIndex
CREATE INDEX "batch_mining_records_batch_idx" ON "batch_mining_records"("batch");

-- CreateIndex
CREATE INDEX "batch_mining_records_account_sequence_idx" ON "batch_mining_records"("account_sequence");

-- AddForeignKey
ALTER TABLE "batch_mining_records" ADD CONSTRAINT "batch_mining_records_execution_id_fkey" FOREIGN KEY ("execution_id") REFERENCES "batch_mining_executions"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
