<?php

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

class CreateSubscriptionCancellations extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('subscription_cancellations')) {
            Schema::create('subscription_cancellations', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('subscription_id')->nullable();

            $table->foreign('subscription_id')
                ->references('id')
                ->on('subscriptions')
                ->constrained()
                ->onDelete('set null')
                ->onUpdate('cascade')
            ;
            $table->text('reason');
                $table->timestamps();
            });
        }

    }

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