<?php

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

class CreateDocumentThemeTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('document_theme', function (Blueprint $table) {
            $table->unsignedBigInteger('document_id');
            $table->unsignedBigInteger('theme_id');
            $table->unsignedInteger('position')->nullable();
            
            $table->primary(['document_id', 'theme_id'], 'document_theme_pk');
            
            $table->foreign('document_id')->references('id')
                ->on('documents')->onDelete('CASCADE')->onUpdate('CASCADE');
            
            $table->foreign('theme_id')->references('id')
                ->on('themes')->onDelete('CASCADE')->onUpdate('CASCADE');
            
            $table->timestamps();
        });
    }

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