<?php

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

class AddBlockHomeFields extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('blocks', function (Blueprint $table) {
            $table->string('bg_type', 20)->nullable();
            $table->smallInteger('overlay_opacity')->nullable();
            $table->string('overlay_color', 7)->nullable();
            $table->string('font_color', 7)->nullable();
            $table->unsignedInteger('video_id')->nullable();

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

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('blocks', function (Blueprint $table) {
            $table->dropForeign(['video_id']);
            $table->dropColumn('bg_type');
            $table->dropColumn('overlay_opacity');
            $table->dropColumn('overlay_color');
            $table->dropColumn('font_color');
            $table->dropColumn('video_id');
        });
    }
}
