<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateReportInspectionsTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
            'report_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
            'inspection_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
            'orden' => ['type' => 'INT', 'constraint' => 5, 'default' => 0],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addUniqueKey(['report_id', 'inspection_id']);
        $this->forge->addForeignKey('report_id', 'reports', 'id', 'CASCADE', 'CASCADE');
        $this->forge->addForeignKey('inspection_id', 'inspections', 'id', 'CASCADE', 'CASCADE');
        $this->forge->createTable('report_inspections');
    }

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