<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateInspectionTemplatesTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
            'code' => ['type' => 'VARCHAR', 'constraint' => 40],
            'name' => ['type' => 'VARCHAR', 'constraint' => 200],
            'form_code' => ['type' => 'VARCHAR', 'constraint' => 40, 'null' => true],
            'revision' => ['type' => 'INT', 'constraint' => 5, 'default' => 1],
            'layout_mode' => ['type' => 'ENUM("checklist","equipment_table")', 'default' => 'checklist'],
            'descripcion' => ['type' => 'TEXT', 'null' => true],
            'activo' => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 1],
            'created_at' => ['type' => 'DATETIME', 'null' => true],
            'updated_at' => ['type' => 'DATETIME', 'null' => true],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addUniqueKey('code');
        $this->forge->createTable('inspection_templates');
    }

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