<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class EnableQuotationRelations extends Migration
{
    public function up()
    {
        $this->db->query("ALTER TABLE clients ENGINE=InnoDB");
        $this->db->query("ALTER TABLE quotations ENGINE=InnoDB");
        $this->db->query("ALTER TABLE quotation_items ENGINE=InnoDB");
        $this->db->query(
            "ALTER TABLE quotations ADD CONSTRAINT quotations_client_fk FOREIGN KEY (client_id) REFERENCES clients(id) ON UPDATE CASCADE ON DELETE RESTRICT",
        );
        $this->db->query(
            "ALTER TABLE quotation_items ADD CONSTRAINT quotation_items_quotation_fk FOREIGN KEY (quotation_id) REFERENCES quotations(id) ON UPDATE CASCADE ON DELETE CASCADE",
        );
    }

    public function down()
    {
        $this->db->query(
            "ALTER TABLE quotation_items DROP FOREIGN KEY quotation_items_quotation_fk",
        );
        $this->db->query(
            "ALTER TABLE quotations DROP FOREIGN KEY quotations_client_fk",
        );
    }
}
