<?php

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

class CreateAppointmentAppointmentTagTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('appointment_appointment_tag', function (Blueprint $table) {
            $table->string('appointment_id');
            $table->unsignedBigInteger('appointment_tag_id');
            
            $table->foreign('appointment_id')
                  ->references('id')
                  ->on('appointments')
                  ->onDelete('cascade');
                  
            $table->foreign('appointment_tag_id')
                  ->references('id')
                  ->on('appointment_tags')
                  ->onDelete('cascade');
                  
            $table->primary(['appointment_id', 'appointment_tag_id']);
        });
    }

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