<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateReportCardAcknowledgements extends Migration
{
    public function up()
    {
        if ($this->db->tableExists('report_card_acknowledgements')) {
            return;
        }

        $this->forge->addField([
            'id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
                'auto_increment' => true,
            ],
            'parent_id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
            ],
            'student_id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
            ],
            'school_year' => [
                'type' => 'VARCHAR',
                'constraint' => 20,
            ],
            'semester' => [
                'type' => 'VARCHAR',
                'constraint' => 20,
            ],
            'viewed_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'signed_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'signed_name' => [
                'type' => 'VARCHAR',
                'constraint' => 120,
                'null' => true,
            ],
            'signer_ip' => [
                'type' => 'VARCHAR',
                'constraint' => 45,
                'null' => true,
            ],
            'created_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'updated_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
        ]);

        $this->forge->addKey('id', true);
        $this->forge->addKey(['parent_id', 'student_id', 'school_year', 'semester'], false, true);
        $this->forge->createTable('report_card_acknowledgements');
    }

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