<?php

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

    class KeywordOccurrence extends Migration
    {

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

                $table->foreign('keyword_id')->references('id')
                    ->on('keywords')->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('keyword_occurrence');
        }

    }
