<?php

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

/**
 * Publishing can be deliberately skipped (already published, duplicate in the
 * channel, another worker holds the lock). Those were recorded as errors (#123).
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('route_articles', function (Blueprint $table) {
            $table->enum('publish_status', ['unpublished', 'publishing', 'published', 'skipped', 'error'])
                ->default('unpublished')
                ->change();
        });
    }

    public function down(): void
    {
        DB::table('route_articles')
            ->where('publish_status', 'skipped')
            ->update(['publish_status' => 'unpublished']);

        Schema::table('route_articles', function (Blueprint $table) {
            $table->enum('publish_status', ['unpublished', 'publishing', 'published', 'error'])
                ->default('unpublished')
                ->change();
        });
    }
};
