<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('ocr_records', function (Blueprint $table) {
            // 添加处理完成时间字段
            $table->timestamp('processed_at')->nullable()->after('total_questions')->comment('OCR处理完成时间');

            // 创建索引
            $table->index('processed_at', 'idx_ocr_records_processed_at');
            $table->index(['status', 'processed_at'], 'idx_ocr_records_status_processed_at');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('ocr_records', function (Blueprint $table) {
            // 删除索引
            $table->dropIndex('idx_ocr_records_status_processed_at');
            $table->dropIndex('idx_ocr_records_processed_at');

            // 删除字段
            $table->dropColumn('processed_at');
        });
    }
};
