<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateInspectionTemplateSectionsTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
            'template_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
            'titulo' => ['type' => 'VARCHAR', 'constraint' => 200],
            'subtitulo' => ['type' => 'VARCHAR', 'constraint' => 200, 'null' => true],
            'orden' => ['type' => 'INT', 'constraint' => 5, 'default' => 0],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addKey('template_id');
        $this->forge->addForeignKey('template_id', 'inspection_templates', 'id', 'CASCADE', 'CASCADE');
        $this->forge->createTable('inspection_template_sections');
    }

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