<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CrearTablaPersona extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'pers_id' => [
                'type' => 'INT',
                'unsigned' => true,
                'auto_increment' => true,
                'null' => false,
            ],
            'pers_primer_nombre' => [
                'type' => 'VARCHAR',
                'constraint' => 50,
                'null' => false,
            ],
            'pers_segundo_nombre' => [
                'type' => 'VARCHAR',
                'constraint' => 50,
                'null' => false,
            ],
            'pers_primer_apellido' => [
                'type' => 'VARCHAR',
                'constraint' => 50,
                'null' => false,
            ],
            'pers_segundo_apellido' => [
                'type' => 'VARCHAR',
                'constraint' => 50,
                'null' => false,
            ],
            'pers_fecha_nac' => [
                'type' => 'DATE',
                'null' => false,
            ],
            'pers_sexo' => [
                'type' => 'VARCHAR',
                'constraint' => 10,
                'null' => false,
            ],
            'pers_num_doc' => [
                'type' => 'VARCHAR',
                'constraint' => 12,
                'null' => false,
            ],
            'pers_ubigeo_nac' => [
                'type' => 'VARCHAR',
                'constraint' => 20,
                'null' => false,
            ],
            'pers_ubigeo_actual' => [
                'type' => 'VARCHAR',
                'constraint' => 20,
                'null' => false,
            ],
            'pers_direccion' => [
                'type' => 'VARCHAR',
                'constraint' => 20,
                'null' => false,
            ],
            'pers_celular' => [
                'type' => 'VARCHAR',
                'constraint' => 20,
                'null' => false,
            ],
            'pers_correo' => [
                'type' => 'VARCHAR',
                'constraint' => 20,
                'null' => true,
            ],
            'pers_foto' => [
                'type' => 'VARCHAR',
                'constraint' => 100,
                'null' => true,
            ],
            'pers_estado' => [
                'type' => 'BOOL',
                'null' => false,
            ],
            'created_at timestamp default current_timestamp',
            'updated_at timestamp default current_timestamp on update current_timestamp'
        ]);

        $this->forge->addKey("pers_id",true);
        $this->forge->addForeignKey('pers_ubigeo_nac', 'ubigeo_peru_districts', 'id');
        $this->forge->addForeignKey('pers_ubigeo_actual', 'ubigeo_peru_districts', 'id');
        $this->forge->createTable("persona");
    }

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