<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('route_articles', function (Blueprint $table) {
            $table->unsignedTinyInteger('publish_attempts')->default(0)->after('publish_status');
            $table->timestamp('next_attempt_at')->nullable()->after('publish_attempts');

            $table->index('next_attempt_at');
        });
    }

    public function down(): void
    {
        Schema::table('route_articles', function (Blueprint $table) {
            $table->dropIndex(['next_attempt_at']);
            $table->dropColumn(['publish_attempts', 'next_attempt_at']);
        });
    }
};
