<?php

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

class CreateClcAppointmentNotesTable extends Migration
{
    public function up()
    {
        if (Schema::hasTable('clc_appointment_notes')) return;

        Schema::create('clc_appointment_notes', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('appointment_id');
            $table->unsignedInteger('user_id')->nullable();
            $table->string('title', 150)->nullable();
            $table->text('notes');
            $table->timestamps();

            $table->foreign('appointment_id')->references('id')->on('clc_appointments')->onDelete('cascade');
            $table->index('appointment_id');
        });
    }

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