<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddFieldsToDevicesTable extends Migration
{
    public function up()
    {
        Schema::table('devices', function (Blueprint $table) {
            if (!Schema::hasColumn('devices', 'gps_location')) {
                $table->string('gps_location')->nullable()->after('module_number');
            }
            if (!Schema::hasColumn('devices', 'hardware_version')) {
                $table->string('hardware_version')->nullable()->after('firmware_version');
            }
        });
    }

    public function down()
    {
        Schema::table('devices', function (Blueprint $table) {
            if (Schema::hasColumn('devices', 'gps_location')) {
                $table->dropColumn('gps_location');
            }
            if (Schema::hasColumn('devices', 'hardware_version')) {
                $table->dropColumn('hardware_version');
            }
        });
    }
}