<?php

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

class CreateClcDoctorDepartmentsTable extends Migration
{
    public function up()
    {
        if (!Schema::hasTable('clc_doctor_departments')) {
            Schema::create('clc_doctor_departments', function (Blueprint $table) {
                $table->increments('id');
                $table->unsignedInteger('doctor_id');
                $table->unsignedInteger('department_id');
                $table->timestamps();

                $table->foreign('doctor_id')->references('id')->on('clc_doctors')->onDelete('cascade');
                $table->foreign('department_id')->references('id')->on('clc_departments')->onDelete('cascade');
                $table->unique(['doctor_id', 'department_id']);
            });
        }
    }

    public function down()
    {
        Schema::dropIfExists('clc_doctor_departments');
    }
}
