<?php

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

class CreateCoursesTable extends Migration
{

	public function up()
	{
		Schema::create('courses', function (Blueprint $table) {
			$table->increments('id');
			$table->string('name');
			$table->char('code', 8);
			$table->char('section', 3);
			$table->integer('program_id')->unsigned();
			$table->integer('user_id')->unsigned();
			$table->timestamps();
			//$table->text('criteria_achieved')->nullable();
			//$table->text('outcomes_achieved')->nullable();
			//$table->text('outcomes_attempted')->nullable();
			$table->char('number', 4)->default('0000');
		});

		Schema::table('courses', function (Blueprint $table) {
			$table->foreign('program_id')->references('id')->on('programs')->onDelete('cascade')->onUpdate('cascade');
			$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
		});
		Schema::table('courses', function (Blueprint $table) {
			$table->integer('semester_id')->unsigned()->default(1)->after('user_id');
		});

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

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop('courses');
	}
}
