<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddBranchOnEmployee extends Migration
{
    public function up()
    {
        $fields = [
            'branch_code' => [
                'type' => 'VARCHAR',
                'constraint' => 25,
                'null' => false,
                'after' => 'company_id',
            ],
        ];

        $this->forge->addColumn('employee', $fields);

        $this->forge->addForeignKey('branch_code', 'company_branch', 'branch_code', 'CASCADE', 'RESTRICT');
        $this->forge->processIndexes('employee');
    }

    public function down()
    {
        $this->forge->dropForeignKey('employee', 'employee_branch_code_foreign');
        $this->forge->processIndexes('employee');
        $this->forge->dropColumn('employee', 'branch_code');
    }
}
