<?php

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

class AlterActivitiesTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::table('activities', function(Blueprint $table)
		{
		    $table->dropForeign('activities_rubric_id_foreign');
			$table->dropColumn('rubric_id');

			DB::statement('SET FOREIGN_KEY_CHECKS=0;');
			DB::statement('ALTER TABLE `activities` MODIFY `course_id` INTEGER UNSIGNED NULL;');
            DB::statement('SET FOREIGN_KEY_CHECKS=1;');
        });
	}


	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::table('activities', function(Blueprint $table)
		{
            DB::statement('SET FOREIGN_KEY_CHECKS=0;');
            DB::statement('ALTER TABLE `activities` MODIFY `course_id` INTEGER UNSIGNED NOT NULL;');
            DB::statement('SET FOREIGN_KEY_CHECKS=1;');

            $table->integer('rubric_id')->unsigned()->nullable();
            $table
                ->foreign('rubric_id')
                ->references('id')
                ->on('rubrics')
                ->onDelete('cascade')
                ->onUpdate('cascade');
        });
	}

}
