<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateTeacherSubjectsTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id'                 => ['type' => 'BIGINT', 'unsigned' => true, 'auto_increment' => true],
            'teacher_id'         => ['type' => 'BIGINT', 'unsigned' => true],
            'subject_id'         => ['type' => 'BIGINT', 'unsigned' => true],
            'academic_period_id' => ['type' => 'BIGINT', 'unsigned' => true],
            'created_at'         => ['type' => 'DATETIME', 'null' => true],
            'updated_at'         => ['type' => 'DATETIME', 'null' => true],
        ]);
        $this->forge->addPrimaryKey('id');
        $this->forge->addForeignKey('teacher_id', 'teachers', 'id', 'CASCADE', 'CASCADE');
        $this->forge->addForeignKey('subject_id', 'subjects', 'id', 'CASCADE', 'CASCADE');
        $this->forge->addForeignKey('academic_period_id', 'academic_periods', 'id', 'CASCADE', 'CASCADE');
        $this->forge->createTable('teacher_subjects');
    }

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