<?php

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

class RemoveIsInvoiceGeneratedFromBookingsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('bookings', function (Blueprint $table) {
            // Drop the index first
            $table->dropIndex('bookings_is_invoice_generated_index');

            // Then drop the column
            $table->dropColumn('is_invoice_generated');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('bookings', function (Blueprint $table) {
            // Re-add the column
            $table->boolean('is_invoice_generated')
                ->default(false)
                ->after('status');

            // Recreate the index
            $table->index('is_invoice_generated', 'bookings_is_invoice_generated_index');
        });
    }
}
