<?php

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

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

            $table->string('title', 255);
            $table->text('description')->nullable();
            $table->text('reading_suggestion')->nullable();
            $table->mediumText('plunder_location')->nullable();
            $table->mediumText('epigraph_title')->nullable();

            // Date
            $table->dateTime('last_update')->nullable();

            // Metas
            $table->string('meta_title', 150)->nullable();
            $table->string('meta_description', 300)->nullable();

            // Languages
            $table->unique(['epigraph_id', 'language_id'], 'idx_epigraph_language');
            $table->foreign('epigraph_id')
                ->references('id')
                ->on('epigraphs')
                ->onDelete('CASCADE')
                ->onUpdate('CASCADE');
        });
    }

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