<?php

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

class AddCroppedToCapsule extends Migration
{
    const TABLE = 'table_capsule';
    const TABLE_PREVIEW = 'table_capsule_preview';

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table(static::TABLE, function (Blueprint $table) {

            $table->unsignedInteger('cropped_id')->nullable();
            $table->foreign('cropped_id')->references('id')->on(static::TABLE_PREVIEW)->onDelete('set null');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table(static::TABLE, function (Blueprint $table) {

            $table->dropForeign(['cropped_id']);
            $table->dropColumn('cropped_id');
        });
    }
}
