<?php

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

class CreateNewsItemLanguagesTable extends Migration {

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

            $table->string('title', 150);
            $table->text('content')->nullable();
            $table->text('cta')->nullable();

            // Languages
            $table->unique(['news_item_id', 'language_id'], 'idx_news_item_language');
            $table->foreign('news_item_id')
                ->references('id')
                ->on('news_items')
                ->onDelete('CASCADE')
                ->onUpdate('CASCADE');
        });
	}

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

}
