<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;
use CodeIgniter\Database\RawSql;

class AddForeignChatDepartmentUsers extends Migration
{
    protected array $COLUMNS = [
        "pedido_id" => [
            "type" => "INT",
            "constraint" => 16,
            "unsigned" => true,
            "null" => true
        ],
        "presupuesto_id" => [
            "type" => "INT",
            "constraint" => 10,
            "unsigned" => true,
            "null" => true
        ],
        "factura_id" => [
            "type" => "INT",
            "constraint" => 10,
            "unsigned" => true,
            "null" => true
        ],
    ];
    public function up()
    {
        $this->forge->addColumn("chat_department_users",$this->COLUMNS);
        $this->forge->addForeignKey('pedido_id', 'pedidos', 'id');
        $this->forge->addForeignKey('factura_id', 'facturas', 'id');
        $this->forge->addForeignKey('presupuesto_id', 'presupuestos', 'id');
    }

    public function down()
    {
        $this->forge->dropForeignKey("chat_department_users","pedido_id");
        $this->forge->dropForeignKey("chat_department_users","factura_id");
        $this->forge->dropForeignKey("chat_department_users","presupuesto_id");
        $this->forge->dropColumn("chat_department_users",["pedido_id","factura_id","presupuesto_id"]);
    }
}
