<?php

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

class AddBlogPostFooterColumns extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('blog_posts', function (Blueprint $table) {
            $table->dateTime('updated_at', 0)->nullable()->default(null)->change();
            $table->unsignedInteger('cta_bar_contact_id')->nullable();
            $table->string('cta_bar_type', 20)->nullable();

            $table->foreign('cta_bar_contact_id')->references('id')
                ->on('contacts')->onDelete('SET NULL')->onUpdate('CASCADE');
        });

        Schema::table('blog_posts_lang', function (Blueprint $table) {
            $table->string('cta_bar_title', 150)->nullable();
            $table->text('cta_bar_text')->nullable();
            $table->text('cta_bar_cta')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('blog_posts_lang', function (Blueprint $table) {
            $table->dropColumn('cta_bar_title');
            $table->dropColumn('cta_bar_text');
            $table->dropColumn('cta_bar_cta');
        });

        Schema::table('blog_posts', function (Blueprint $table) {
            $table->dropForeign(['cta_bar_contact_id']);
            $table->dropColumn('cta_bar_contact_id');
            $table->dropColumn('cta_bar_type');
        });
    }
}
