<?php namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class Create_loans extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id'=>['type'=>'BIGINT','unsigned'=>true,'auto_increment'=>true],
            'loan_uid'=>['type'=>'VARCHAR','constraint'=>64],
            'user_id'=>['type'=>'BIGINT','unsigned'=>true],
            'product_id'=>['type'=>'INT','unsigned'=>true],
            'amount'=>['type'=>'DECIMAL','constraint'=>'12,2'],
            'term'=>['type'=>'INT'],
            'interest_rate'=>['type'=>'DECIMAL','constraint'=>'10,4'],
            'processing_fee'=>['type'=>'DECIMAL','constraint'=>'12,2','default'=>0],
            'status'=>['type'=>'VARCHAR','constraint'=>30,'default'=>'pending'],
            'disbursed_at'=>['type'=>'DATETIME','null'=>true],
            'closed_at'=>['type'=>'DATETIME','null'=>true],
            'created_at'=>['type'=>'DATETIME','null'=>true],
            'updated_at'=>['type'=>'DATETIME','null'=>true],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addKey('loan_uid');
        $this->forge->createTable('loans');
    }

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