<?php

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

class CreateJobsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // Only create if it doesn't exist (Laravel queue migration might have already created it)
        if (!Schema::hasTable('jobs')) {
            Schema::create('jobs', function (Blueprint $table) {
                $table->increments('id');
                $table->string('desc');
            });
        } else {
            // Check if it's the Laravel queue table (has 'queue' column)
            $columns = Schema::getColumnListing('jobs');
            if (in_array('queue', $columns)) {
                // Drop Laravel queue jobs table and create employee jobs table
                Schema::dropIfExists('jobs');
                Schema::create('jobs', function (Blueprint $table) {
                    $table->increments('id');
                    $table->string('desc');
                });
            } elseif (!in_array('desc', $columns)) {
                // Jobs table exists but doesn't have 'desc' column, add it
                Schema::table('jobs', function (Blueprint $table) {
                    $table->string('desc')->after('id');
                });
            }
        }
    }

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