<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CrearTablaUsuario extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'usua_id' => [
                'type' => 'INT',
                'unsigned' => true,
                'auto_increment' => true,
                'null' => false,
            ],
            'pers_id' => [
                'type' => 'VARCHAR',
                'constraint' => 50,
                'null' => false,
            ],
            'usua_usuario' => [
                'type' => 'VARCHAR',
                'constraint' => 200,
                'null' => true,
            ],
            'usua_contrasena' => [
                'type' => 'VARCHAR',
                'constraint' => 200,
                'null' => true,
            ],
            'usua_estado' => [
                'type' => 'BOOL',
                'null' => false,
            ],
            
            'created_at timestamp default current_timestamp',
            'updated_at timestamp default current_timestamp on update current_timestamp'
        ]);

        $this->forge->addKey("usua_id",true);
        $this->forge->addForeignKey('pers_id', 'persona', 'pers_id');
        $this->forge->createTable("usuario");
    }

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