<?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
    {
        if (Schema::hasTable('knowledge_base') && !Schema::hasColumn('knowledge_base', 'source_category')) {
            Schema::table('knowledge_base', function (Blueprint $table) {
                $table->string('source_category', 40)->default('custom')->index()->after('normalized_key');
            });
        }
    }

    public function down(): void
    {
        if (Schema::hasTable('knowledge_base') && Schema::hasColumn('knowledge_base', 'source_category')) {
            Schema::table('knowledge_base', function (Blueprint $table) {
                $table->dropColumn('source_category');
            });
        }
    }
};
