<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateAscPeriods extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type'           => 'INT',
                'constraint'     => 11,
                'unsigned'       => true,
                'auto_increment' => true,
            ],
            'import_id' => [
                'type'     => 'INT',
                'constraint' => 11,
                'unsigned' => true,
            ],
            'period_number' => [
                'type'       => 'TINYINT',
                'constraint' => 2,
                'comment'    => 'Jam ke- (1, 2, 3, ...)',
            ],
            'name' => [
                'type'       => 'VARCHAR',
                'constraint' => 20,
                'comment'    => 'Nama periode dari XML',
            ],
            'start_time' => [
                'type'       => 'VARCHAR',
                'constraint' => 10,
                'comment'    => 'Misal: 07:00',
            ],
            'end_time' => [
                'type'       => 'VARCHAR',
                'constraint' => 10,
                'comment'    => 'Misal: 07:40',
            ],
            'created_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'updated_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
        ]);

        $this->forge->addKey('id', true);
        $this->forge->addKey('import_id');
        $this->forge->createTable('asc_periods');
    }

    public function down()
    {
        $this->forge->dropTable('asc_periods');
    }
}