<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use MtcPharmacy\Subscriptions\Classes\Subscription;

class CreateSubscriptionsOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('subscriptions_orders')) {
            Schema::create('subscriptions_orders', function (Blueprint $table) {
                $table->increments('id');
                $table->unsignedInteger('subscription_id');
                $table->integer('order_id');
                $table->timestamp('created_at')->useCurrent();

                $table->foreign('subscription_id')
                    ->references('id')
                    ->on('subscriptions')
                    ->constrained()
                    ->onDelete('cascade')
                    ->onUpdate('cascade');

                $table->foreign('order_id')
                    ->references('id')
                    ->on('order')
                    ->constrained()
                    ->onDelete('cascade')
                    ->onUpdate('cascade');
            });
        }
    }

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

