<?php

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

class CreateDocumentLanguagesTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
        Schema::create('document_languages', function (Blueprint $table) {
            $table->bigIncrements('translation_id');
            $table->unsignedBigInteger('document_id');
            $table->string('language_id', 10);

            $table->string('title', 150);
            $table->string('name', 255)->nullable();

            // Languages
            $table->unique(['document_id', 'language_id'], 'idx_document_language');
            $table->foreign('document_id')
                ->references('id')
                ->on('documents')
                ->onDelete('CASCADE')
                ->onUpdate('CASCADE');
        });
	}

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

}
