<?php

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

class CreateChronologyLanguagesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('chronology_languages', function (Blueprint $table) {
            $table->bigIncrements('translation_id');
            
            $table->unsignedBigInteger('chronology_id');
            $table->string('language_id', 10);
            
            $table->string('title', 150);
            $table->integer('date_start');
            $table->integer('date_end');
            $table->string('descriptive_text', 250)->nullable();
            
            $table->unique(['chronology_id', 'language_id'], 'idx_chronology_lang');
            $table->foreign('chronology_id')
                ->references('id')
                ->on('chronologies')
                ->onDelete('CASCADE')
                ->onUpdate('CASCADE');
            
            $table->timestamps();
        });
    }

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