<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CrearAlumnoPlaEstudio extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'alpe_id' => [
                'type' => 'INT',
                'unsigned' => true,
                'auto_increment' => true,
                'null' => false,
            ],
            'alum_id' => [
                'type' => 'INT',
                'unsigned' => true,
                'null' => false,
            ],
            'plaest_id' => [
                'type' => 'INT',
                'unsigned' => true,
                'null' => false,
            ],
            'peraca_id' => [
                'type' => 'INT',
                'unsigned' => true,
                'null' => false,
            ],
            'alpe_estado' => [
                'type' => 'BOOL',
                'null' => false,
            ],
            'created_at timestamp default current_timestamp',
            'updated_at timestamp default current_timestamp on update current_timestamp'
        ]);

        $this->forge->addKey("alpe_id",true);
        $this->forge->addForeignKey('alum_id', 'alumno', 'alum_id');
        $this->forge->addForeignKey('plaest_id', 'plan_estudio', 'plaest_id');
        $this->forge->addForeignKey('peraca_id', 'periodo_academico', 'peraca_id');
        $this->forge->createTable("alumno_plan_estudio");
    }

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