<?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('class_schedule_exceptions', function (Blueprint $table) {
            // course_id：override/add 時可指定課程
            $table->foreignId('course_id')
                ->nullable()
                ->after('action')
                ->constrained('class_courses')
                ->nullOnDelete()
                ->comment('課程');

            $table->index(['course_id']);
        });
    }

    public function down(): void
    {
        Schema::table('class_schedule_exceptions', function (Blueprint $table) {
            $table->dropForeign(['course_id']);
            $table->dropIndex(['course_id']);
            $table->dropColumn('course_id');
        });
    }
};
