<?php

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

class CreateOpenworkJobRecordsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('openwork_job_records', function (Blueprint $table) {
            $table->id();
            $table->string('job_id', 255)->unique(); // Laravel 队列任务的 ID
            $table->string('name'); // 任务类名
            $table->text('payload')->nullable(); // 任务数据
            $table->string('status')->default('pending'); // pending, processing, completed, failed
            $table->text('result')->nullable(); // 任务结果
            $table->text('exception')->nullable(); // 异常信息
            $table->timestamp('started_at')->nullable();
            $table->timestamp('finished_at')->nullable();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('openwork_job_records');
    }
}
