<?php

namespace App\Database\Migrations;

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

class MaquinaOtTareasTable extends Migration
{
    protected array $COLUMNS = [

        'id' =>  [
            'type' => 'INT',
            'unsigned' => true,
            'auto_increment' => true,
        ],
        'maquina_id' => [
            'type' => 'INT',
            'unsigned' => true,
            'constraint' => 11
        ],
        'orden_trabajo_id' => [
            'type' => 'INT',
            'unsigned' => true,
        ],

    ];

    public function up()
    {
        $this->forge->addField($this->COLUMNS);
        $currenttime = new RawSql('CURRENT_TIMESTAMP');
        $this->forge->addField([
            'created_at' => [
                'type' => 'TIMESTAMP',
                'default' => $currenttime,
            ],
            'updated_at' => [
                'type' => 'TIMESTAMP',
                'null' => true,
            ],
            'deleted_at' => [
                'type' => 'TIMESTAMP',
                'null' => true,

            ],
        ]);
        $this->forge->addPrimaryKey('id');
        $this->forge->addForeignKey('maquina_id','lg_maquinas','id','CASCADE','CASCADE','maquina_ot_tareas_maquina_id_fk');
        $this->forge->addForeignKey('orden_trabajo_id','ordenes_trabajo','id','CASCADE','CASCADE','maquina_ot_tareas_ot_id_fk');
        $this->forge->createTable("maquina_ot_tareas");
    }

    public function down()
    {
        $this->forge->dropTable("maquina_ot_tareas");
    }
}
