<?php
// database/migrations/xxxx_xx_xx_xxxxxx_add_attachment_type_to_file_attachments.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('file_attachments', function (Blueprint $table) {
            $table->foreignId('attachment_type_id')
                ->nullable()
                ->after('notice_update_id')
                ->constrained('attachment_types')
                ->onDelete('set null');
        });
    }

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