<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddGeoFenceToDevicesTable extends Migration
{
    public function up()
    {
        $fields = [
            'latitude' => [
                'type'       => 'DECIMAL',
                'constraint' => '10,8',
                'null'       => true,
                'after'      => 'last_seen_at',
            ],
            'longitude' => [
                'type'       => 'DECIMAL',
                'constraint' => '11,8',
                'null'       => true,
                'after'      => 'latitude',
            ],
            'radius_meters' => [
                'type'       => 'INT',
                'constraint' => 11,
                'null'       => true,
                'after'      => 'longitude',
            ],
        ];

        $this->forge->addColumn('devices', $fields);
    }

    public function down()
    {
        $this->forge->dropColumn('devices', ['latitude', 'longitude', 'radius_meters']);
    }
}

