<?php

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

    class LocationOccurrence extends Migration
    {

        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
            Schema::create('location_occurrence', function (Blueprint $table) {
                $table->unsignedInteger('location_id');
                $table->unsignedInteger('occurrence_id');
                $table->integer('position')->nullable();
                $table->primary(['location_id', 'occurrence_id']);

                $table->foreign('location_id')->references('id')
                    ->on('locations')->onDelete('CASCADE')->onUpdate('CASCADE');
                $table->foreign('occurrence_id')->references('id')
                    ->on('occurrences')->onDelete('CASCADE')->onUpdate('CASCADE');
            });
        }

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

    }
