-- AlterTable: 添加 phase 和 days_in_phase 字段到 batch_mining_records
ALTER TABLE "batch_mining_records" ADD COLUMN "phase" INTEGER NOT NULL DEFAULT 1;
ALTER TABLE "batch_mining_records" ADD COLUMN "days_in_phase" INTEGER NOT NULL DEFAULT 0;

-- DropIndex: 删除旧的唯一约束
DROP INDEX IF EXISTS "batch_mining_records_execution_id_account_sequence_key";

-- CreateIndex: 创建新的唯一约束（包含 phase）
CREATE UNIQUE INDEX "batch_mining_records_execution_id_account_sequence_phase_key" ON "batch_mining_records"("execution_id", "account_sequence", "phase");

-- CreateIndex: 为 phase 创建索引
CREATE INDEX "batch_mining_records_phase_idx" ON "batch_mining_records"("phase");

-- 移除默认值（可选，因为新数据会明确指定值）
ALTER TABLE "batch_mining_records" ALTER COLUMN "phase" DROP DEFAULT;
ALTER TABLE "batch_mining_records" ALTER COLUMN "days_in_phase" DROP DEFAULT;
