<?php

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

class EntriesAddMetas extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
        Schema::table('entries_lang', function (Blueprint $table) {
            $table->string('meta_title', 150)->nullable()->after('content');
            $table->string('meta_description', 300)->nullable()->after('meta_title');
        });

        Schema::table('entries', function (Blueprint $table) {
            $table->unsignedBigInteger('meta_image_id')->nullable();
            $table->foreign('meta_image_id')->references('id')
                ->on('media_items')->onDelete('SET NULL')->onUpdate('CASCADE');
        });
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
        Schema::table('entries_lang', function (Blueprint $table) {
            $table->dropColumn('meta_title');
            $table->dropColumn('meta_description');
        });

        Schema::table('entries', function (Blueprint $table) {
            $table->dropForeign('entries_meta_image_id_foreign');
            $table->dropColumn('meta_image_id');
        });
	}

}
