<?php

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

class AddDiscountPercentageToSubscriptionPreferences extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('subscription_preferences', function (Blueprint $table) {
            if (!Schema::hasColumn('subscription_preferences', 'discount_percentage')) {
                $table->double('discount_percentage')->nullable()->default(0)->after('interval');
            }
        });

    }

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

    }
}
