<?php

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

class AddSemesterIdToCourseStudentTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::table('course_student', function(Blueprint $table)
		{
			$table->integer('semester_id')->unsigned()->default(1)->after('student_id');
		});

		Schema::table('course_student', function(Blueprint $table)
		{
			$table->foreign('semester_id')->references('id')->on('semesters');
		});
	}


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

}
