<?php

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

class DropForeignKeyAndRemoveColumnFromActivitiesTable extends Migration {

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

		Schema::table('rubrics', function(Blueprint $table)
		{
			$table->integer('activity_id')->unsigned();
			$table->foreign('activity_id')->references('id')->on('activities')->onDelete('cascade')->onUpdate('cascade');
		});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::table('activities', function(Blueprint $table)
		{
			$table->integer('rubric_id')->unsigned()->nullable();
			$table->foreign('rubric_id')->references('id')->on('rubrics')->onDelete('cascade')->onUpdate('cascade');
		});

		Schema::table('rubrics', function(Blueprint $table)
		{
			$table->dropForeign('activity_id');
			$table->dropColumn('activity_id');
		});
	}

}
