<?php

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

class AlterWalletCompanyId extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasColumn('wallets', 'company_id')) {
            Schema::table('wallets', function (Blueprint $table) {
                $table->dropForeign('wallets_company_id_foreign');
                $table->dropColumn('company_id');
            });
        }

        if (!Schema::hasColumn('wallets', 'owner_id')) {
            Schema::table('wallets', function (Blueprint $table) {
                $table->morphs('owner');
            });

            //In-case the model name lengthy
            Schema::table('wallets', function (Blueprint $table) {
                $table->string('owner_type', 250)->change();
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}
