<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateDeliveryNoteInspectionsTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
            'delivery_note_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
            'inspection_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
            'orden' => ['type' => 'INT', 'constraint' => 11, 'default' => 0],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addKey(['delivery_note_id', 'inspection_id']);
        $this->forge->addForeignKey('delivery_note_id', 'delivery_notes', 'id', 'CASCADE', 'CASCADE');
        $this->forge->addForeignKey('inspection_id', 'inspections', 'id', 'RESTRICT', 'CASCADE');
        $this->forge->createTable('delivery_note_inspections');
    }

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