<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateArchiveEntryTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('archive_entry', function (Blueprint $table) {
            $table->unsignedInteger('entry_id');
            $table->unsignedInteger('archive_id');
            $table->unsignedInteger('position')->nullable();

            $table->primary(['entry_id', 'archive_id'], 'entry_archive_pk');
            $table->foreign('entry_id')->references('id')
                ->on('entries')->onDelete('CASCADE')->onUpdate('CASCADE');
            $table->foreign('archive_id')->references('id')
                ->on('archives')->onDelete('CASCADE')->onUpdate('CASCADE');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('archive_entry');
    }
}
