<?php

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

class CreateProfessorSemesterTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('professor_semester', function (Blueprint $table) {
            $table->unsignedBigInteger('professor_id');
            $table->char('semester_code', 3);
            $table->decimal('admin_load')->nullable();
            $table->decimal('investigative_load')->nullable();

            $table->foreign('professor_id')->references('id')->on('professors');
            $table->foreign('semester_code')->references('code')->on('semesters');

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

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