<?php

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

class CreateChronologyPropertyTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('chronology_property', function (Blueprint $table) {
            $table->unsignedBigInteger('chronology_id');
            $table->unsignedBigInteger('property_id');
            $table->unsignedInteger('position')->nullable();
            
            $table->primary(['chronology_id', 'property_id'], 'chronology_property_pk');
            
            $table->foreign('chronology_id')->references('id')
                ->on('chronologies')->onDelete('CASCADE')->onUpdate('CASCADE');
            
            $table->foreign('property_id')->references('id')
                ->on('properties')->onDelete('CASCADE')->onUpdate('CASCADE');
            
            $table->timestamps();
        });
    }

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