<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CrearTablaPlanEstudioCurso extends Migration
{
    
    public function up(){
        $this->forge->addField([
            'plaescu_id' => [
                'type' => 'INT',
                'unsigned' => true,
                'auto_increment' => true,
                'null' => false,
            ],
            'plaest_id' => [
                'type' => 'INT',
                'unsigned' => true,
                'null' => false,
            ],
            'curso_id' => [
                'type' => 'INT',
                'unsigned' => true,
                'null' => false,
            ],
            'ciclo_id' => [
                'type' => 'INT',
                'unsigned' => true,
                'null' => false,
            ],
            'plaescu_codigo' => [
                'type' => 'VARCHAR',
                'constraint' => 20,
                'null' => true,
            ],
            'plaescu_hr_teoria' => [
                'type' => 'DECIMAL',
                'constraint' => 10,2,
                'null' => true,
            ],
            'plaescu_hr_practica' => [
                'type' => 'DECIMAL',
                'constraint' => 10,2,
                'null' => true,
            ],
            'plaescu_hr_seminario' => [
                'type' => 'DECIMAL',
                'constraint' => 10,2,
                'null' => true,
            ],
            'plaescu_hr_virtual' => [
                'type' => 'DECIMAL',
                'constraint' => 10,2,
                'null' => true,
            ],
            'plaescu_creditos' => [
                'type' => 'INT',
                'unsigned' => true,
                'null' => false,
            ],
            'plaescu_tipo' => [
                'type' => 'VARCHAR',
                'constraint' => '25',
                'null' => true,
            ],
            'plaescu_estado' => [
                'type' => 'BOOL',
                'null' => false,
            ],         
            'created_at timestamp default current_timestamp',
            'updated_at timestamp default current_timestamp on update current_timestamp'
        ]);

        $this->forge->addKey("plaescu_id", true);
        $this->forge->addForeignKey('plaest_id', 'plan_estudio', 'plaest_id');
        $this->forge->addForeignKey('curso_id', 'curso', 'curso_id');
        $this->forge->addForeignKey('ciclo_id', 'ciclo', 'ciclo_id');
        $this->forge->createTable("plan_estudio_curso");
    }

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