<?php

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

class DropAssignedMarketingUserIdFromTradefairsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasColumn('tradefairs', 'assigned_marketing_user_id')) {
            return;
        }

        Schema::table('tradefairs', function (Blueprint $table) {
            $table->dropForeign(['assigned_marketing_user_id']);
            $table->dropColumn('assigned_marketing_user_id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('tradefairs', function (Blueprint $table) {
            $table->unsignedBigInteger('assigned_marketing_user_id')->nullable()->index()->after('status');
            $table->foreign('assigned_marketing_user_id')->references('id')->on('users')->nullOnDelete();
        });
    }
}
