<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateDriverLocations extends Migration
{
    public function up(): void
    {
        $this->forge->addField([
            'id' => [
                'type'           => 'INT',
                'constraint'     => 11,
                'unsigned'       => true,
                'auto_increment' => true,
            ],
            'user_id' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
            ],
            'latitude' => [
                'type' => 'DOUBLE',
            ],
            'longitude' => [
                'type' => 'DOUBLE',
            ],
            'updated_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addUniqueKey('user_id');
        $this->forge->addForeignKey('user_id', 'users', 'id', 'CASCADE', 'CASCADE');
        $this->forge->createTable('driver_locations');
    }

    public function down(): void
    {
        $this->forge->dropTable('driver_locations');
    }
}
