<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateRawAttLog extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'company_issued_id' => [
                'type' => 'VARCHAR',
                'constraint' => 25,
                'null' => true,
            ],
            'log_date' => [
                'type' => 'DATE',
                'null' => true,
            ],
            'log_time' => [
                'type' => 'TIME',
                'null' => true,
            ],
            'ucol1' => [
                'type' => 'VARCHAR',
                'constraint' => 2,
                'null' => true,
            ],
            'log_type' => [
                'type' => 'TINYINT',
                'constraint' => 1,
                'null' => true,
            ],
            'ucol2' => [
                'type' => 'VARCHAR',
                'constraint' => 2,
                'null' => true,
            ],
            'ucol3' => [
                'type' => 'VARCHAR',
                'constraint' => 2,
                'null' => true,
            ],
            'branch_code' => [
                'type' => 'VARCHAR',
                'constraint' => 25,
                'null' => false,
            ],
            'att_from' => [
                'type' => 'DATE',
                'null' => true,
            ],
            'att_to' => [
                'type' => 'DATE',
                'null' => true,
            ],

            // Common fields
            'created_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'created_by' => [
                'type' => 'VARCHAR', 
                'constraint' => '20', 
                'null' => true
            ],
        ]);

        $this->forge->addKey(['company_issued_id', 'log_date', 'log_time', 'log_type'], true);
        $this->forge->createTable('raw_att_log');
    }

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