<?php

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

class AlterTasksTableDropKeychainIdColumn extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		$columns = collect(DB::select('SHOW COLUMNS FROM tasks'))->pluck('Field')->toArray();
		if (in_array('keychain_id', $columns)) {
			Schema::table('tasks', function($table){
				$table->dropColumn('keychain_id');
			});
		}
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::table('tasks', function($table){
			$table->unsignedBigInteger('keychain_id');
		});
	}

}
