<?php

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

class CreateEntriesLangTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('entries_lang', function (Blueprint $table) {
            $table->bigIncrements('translation_id');
            $table->unsignedBigInteger('entry_id');
            $table->string('language_id', 10);
            $table->string('title', 150)->nullable();
            $table->mediumText('content')->nullable();

            $table->unique(['entry_id', 'language_id'], 'idx_entry_lang');

            $table->foreign('entry_id')->references('id')
                ->on('entries')->onDelete('CASCADE')->onUpdate('CASCADE');
        });
    }

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