<?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('subject_curriculum_items') || Schema::hasColumn('subject_curriculum_items', 'school_year')) {
            return;
        }

        Schema::table('subject_curriculum_items', function (Blueprint $table) {
            $table->string('school_year', 20)->nullable()->after('class_id')->index();
        });
    }

    public function down(): void
    {
        if (! Schema::hasTable('subject_curriculum_items') || ! Schema::hasColumn('subject_curriculum_items', 'school_year')) {
            return;
        }

        Schema::table('subject_curriculum_items', function (Blueprint $table) {
            $table->dropColumn('school_year');
        });
    }
};
