<?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('posts', function (Blueprint $t) {
            if (! Schema::hasColumn('posts', 'default_master_id')) {
                $t->foreignId('default_master_id')->nullable()->after('hours_per_day')->constrained('users')->nullOnDelete();
            }
        });
    }

    public function down(): void
    {
        Schema::table('posts', function (Blueprint $t) {
            if (Schema::hasColumn('posts', 'default_master_id')) {
                $t->dropForeign(['default_master_id']);
                $t->dropColumn('default_master_id');
            }
        });
    }
};
