<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateRewarderAdminApiTokens extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
            'user_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
            'token_hash' => ['type' => 'VARCHAR', 'constraint' => 64],
            'created_at' => ['type' => 'DATETIME', 'null' => true],
            'expires_at' => ['type' => 'DATETIME', 'null' => true],
            'revoked_at' => ['type' => 'DATETIME', 'null' => true],
            'last_used_at' => ['type' => 'DATETIME', 'null' => true],
        ]);

        $this->forge->addKey('id', true);
        $this->forge->addKey(['user_id']);
        $this->forge->addKey(['token_hash'], false, true);
        $this->forge->createTable('rewarder_admin_api_tokens', true);
    }

    public function down()
    {
        $this->forge->dropTable('rewarder_admin_api_tokens', true);
    }
}

