<?php

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

class AddEmailConfirmTokenToVcPetOwnerDetails extends Migration
{
    public function up()
    {
        if (!Schema::hasTable('vc_pet_owner_details')) return;

        Schema::table('vc_pet_owner_details', function (Blueprint $table) {
            if (!Schema::hasColumn('vc_pet_owner_details', 'email_confirmed')) {
                $table->boolean('email_confirmed')->default(false)->after('notes');
            }
            if (!Schema::hasColumn('vc_pet_owner_details', 'email_confirm_token')) {
                $table->string('email_confirm_token', 100)->nullable();
            }
            if (!Schema::hasColumn('vc_pet_owner_details', 'email_confirm_sent_at')) {
                $table->timestamp('email_confirm_sent_at')->nullable();
            }
        });
    }

    public function down()
    {
        Schema::table('vc_pet_owner_details', function (Blueprint $table) {
            $table->dropColumn(['email_confirm_token', 'email_confirm_sent_at']);
        });
    }
}
