<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;
use CodeIgniter\Database\RawSql;
class CreateUsersTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'uid' => [
                    'type' => 'INT',
                    'constraint' => 5,
                    'unsigned' => true,
                    'auto_increment' => true,
            ],
            'id' => [
                    'type' => 'VARCHAR',
                    'constraint' => '20',
                    'unique'     => true,
            ],
            'passwd' => [
                    'type' => 'VARCHAR',
                    'constraint' => '150',
            ],
            'name' => [
                    'type' => 'VARCHAR',
                    'constraint' => '20',
            ],
            'email' => [
                    'type' => 'VARCHAR',
                    'constraint' => '50',
                    'unique'     => true,
            ],
            'role' => [
                    'type' => 'VARCHAR',
                    'constraint' => 10,
                    'default'    => DEFAULT_ROLE,
            ],
            'status' => [
                    'type' => 'VARCHAR',
                    'constraint' => 10,
                    'default'    => DEFAULT_STATUS,
            ],
            'updated_at' => [
                'type'    => 'TIMESTAMP',
                'default' => null,
            ], 
            'created_at' => [
                'type'    => 'TIMESTAMP',
                'default' => new RawSql('CURRENT_TIMESTAMP'),
            ],      
        ]);
        $this->forge->addPrimaryKey('uid');
        $this->forge->createTable('user');
    }

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