<?php

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

class AddCriteriaIdToAssessmentsTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::table('assessments', function(Blueprint $table)
		{
			$table->integer('criterion_id')->unsigned();

			$table
                ->foreign('criterion_id')
                ->references('id')
                ->on('criteria')
                ->onDelete('cascade')
                ->onUpdate('cascade');
		});
	}


	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::table('assessments', function(Blueprint $table)
		{
		    $table->dropForeign('assessments_criterion_id_foreign');
		    $table->dropColumn('criterion_id');
		});
	}

}
