<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class Personnel extends Migration
{
    public function up()
    {
        //
        $this->forge->addField([
            'id'             => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
            'nom'            => ['type' => 'VARCHAR', 'constraint' => 100],
            'prenom'         => ['type' => 'VARCHAR', 'constraint' => 100],
            'telephone'      => ['type' => 'INT' ],
            'matricule'      => ['type' => 'INT', 'unique' => true],
            'sexe'           => ['type' => 'ENUM("h","f")'],
            'code_str'       => ['type' => 'INT', 'unsigned' => true, 'null' => false],
            'created_at'     => ['type' => 'DATETIME', 'null' => true],
            'updated_at'     => ['type' => 'DATETIME', 'null' => true],
            'deleted_at'     => ['type' => 'DATETIME', 'null' => true],
        ]);
        
        $this->forge->addKey('id', true); // Primary key
        $this->forge->addForeignKey('code_str', 'structure', 'code_str', 'CASCADE', 'CASCADE');
        $this->forge->createTable('personnel');
    }

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