<?php

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

class CreateSectionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('sections', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->char('semester_code', 3);
            $table->unsignedBigInteger('course_id');
            $table->char('code', 3);
            $table->unsignedInteger('student_count')->nullable();
            $table->string('syllabus')->nullable();
            $table->unsignedDecimal('credits')->nullable();


            $table->foreign('semester_code')->references('code')->on('semesters');
            $table->foreign('course_id')->references('id')->on('courses');

            $table->unique(['semester_code', 'course_id', 'code']);
        });
    }

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