<?php

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

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

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