<?php

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

class CreateOverlayBlocksTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('overlay_blocks', function (Blueprint $table) {
            $table->integerIncrements('id');
            $table->nullableTimestamps();
            $table->string('type', 20);
            $table->unsignedInteger('backend_user_id')->nullable();
            $table->unsignedInteger('overlay_id');
            $table->unsignedInteger('image1_id')->nullable();
            $table->unsignedInteger('image2_id')->nullable();

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

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

            $table->foreign('backend_user_id')->references('id')
                ->on('backend_users')->onDelete('SET NULL')->onUpdate('CASCADE');

            $table->foreign('overlay_id')->references('id')
                ->on('overlays')->onDelete('CASCADE')->onUpdate('CASCADE');
        });
    }

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