<?php

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

class CreateCapsuleTeaserTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('table_capsule_teaser', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->uuid('uuid')->unique();

            $table->unsignedInteger('duration')->nullable();
            $table->string('hash')->nullable();
            $table->string('ext')->nullable();
            $table->string('mime_type')->nullable();
            $table->string('size')->nullable();

            $table->string('aws_key')->nullable();
            $table->string('aws_bucket')->nullable();

            $table->timestamps();

            $table->softDeletes();
        });

        Schema::table('table_capsule', function (Blueprint $table) {
            $table->unsignedInteger('teaser_id')->nullable();

            $table->foreign('teaser_id')->references('id')->on('table_capsule_teaser')->onDelete('set null');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('table_capsule', function (Blueprint $table) {
            $table->dropColumn('teaser_id');
        });
        Schema::dropIfExists('table_capsule_teaser');
    }
}
