<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateExchangeRatesTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => ['type' => 'BIGINT', 'unsigned' => true, 'auto_increment' => true],
            'currency_from' => ['type' => 'VARCHAR', 'constraint' => 3],
            'currency_to' => ['type' => 'VARCHAR', 'constraint' => 3],
            'rate' => ['type' => 'DECIMAL', 'constraint' => '12,6'],
            'date' => ['type' => 'DATE'],
            'created_at' => ['type' => 'DATETIME', 'null' => true],
            'updated_at' => ['type' => 'DATETIME', 'null' => true],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addUniqueKey(['currency_from', 'currency_to', 'date']);
        $this->forge->createTable('exchange_rates');
    }

    public function down()
    {
        $this->forge->dropTable('exchange_rates');
    }
}
