<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up()
    {
        Schema::table('manufacturing_runs', function (Blueprint $table) {

            // Drop old foreign key (users table)
            // $table->dropForeign(['superviser_employee_id']);

            // Optional: rename column if name is misleading
            // $table->renameColumn('superviser_employee_id', 'superviser_account_id');

            // Add new foreign key (accounts table)
            $table->foreign('superviser_employee_id')
                  ->references('id')
                  ->on('accounts')
                  ->onDelete('restrict'); // or cascade / set null
        });
    }

    public function down()
    {
        Schema::table('manufacturing_runs', function (Blueprint $table) {

            $table->dropForeign(['superviser_employee_id']);

            $table->foreign('superviser_employee_id')
                  ->references('id')
                  ->on('users')
                  ->onDelete('restrict');
        });
    }
};
