<?php

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

class AddHasRequestedSubscriptionPeriodsFields extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('basket_items', function (Blueprint $table) {
            if (!Schema::hasColumn('basket_items', 'has_requested_subscription_period')) {
                $table->string('has_requested_subscription_period', 32)->nullable()->after('has_requested_subscription');
            }
        });

        Schema::table('order_items', function (Blueprint $table) {
            if (!Schema::hasColumn('order_items', 'has_requested_subscription_period')) {
            $table->string('has_requested_subscription_period', 32)->nullable()->after('has_requested_subscription');
            }
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('basket_items', function (Blueprint $table) {
            if (Schema::hasColumn('basket_items', 'has_requested_subscription_period')) {
                $table->dropColumn('has_requested_subscription_period');
            }
        });

        Schema::table('order_items', function (Blueprint $table) {
            if (Schema::hasColumn('order_items', 'has_requested_subscription_period')) {
                $table->dropColumn('has_requested_subscription_period');
            }
        });
    }
}
