nhance/app/Database/Migrations/2026-08-01-043000_AddDependentApprovalTrackingColumns.php

82 lines
2.9 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class AddDependentApprovalTrackingColumns extends Migration
{
public function up()
{
// employees: who created the dependent request, who approved (HR / ACM)
if (! $this->db->fieldExists('emp_created_by', 'employees')) {
$this->forge->addColumn('employees', [
'emp_created_by' => [
'type' => 'VARCHAR',
'constraint' => 50,
'null' => true,
'default' => null,
'after' => 'emp_status',
'comment' => 'Creator role: HR / USER',
],
]);
}
if (! $this->db->fieldExists('approved_by', 'employees')) {
$this->forge->addColumn('employees', [
'approved_by' => [
'type' => 'VARCHAR',
'constraint' => 50,
'null' => true,
'default' => null,
'after' => 'emp_created_by',
'comment' => 'Approver role: HR / ACM',
],
]);
}
// employee_polices: who created the policy row, who approved (HR / ACM)
if (! $this->db->fieldExists('emp_policy_created_by', 'employee_polices')) {
$this->forge->addColumn('employee_polices', [
'emp_policy_created_by' => [
'type' => 'VARCHAR',
'constraint' => 50,
'null' => true,
'default' => null,
'after' => 'status',
'comment' => 'Creator role: HR / USER',
],
]);
}
if (! $this->db->fieldExists('approved_by', 'employee_polices')) {
$this->forge->addColumn('employee_polices', [
'approved_by' => [
'type' => 'VARCHAR',
'constraint' => 50,
'null' => true,
'default' => null,
'after' => 'emp_policy_created_by',
'comment' => 'Approver role: HR / ACM',
],
]);
}
}
public function down()
{
if ($this->db->fieldExists('approved_by', 'employees')) {
$this->forge->dropColumn('employees', 'approved_by');
}
if ($this->db->fieldExists('emp_created_by', 'employees')) {
$this->forge->dropColumn('employees', 'emp_created_by');
}
if ($this->db->fieldExists('approved_by', 'employee_polices')) {
$this->forge->dropColumn('employee_polices', 'approved_by');
}
if ($this->db->fieldExists('emp_policy_created_by', 'employee_polices')) {
$this->forge->dropColumn('employee_polices', 'emp_policy_created_by');
}
}
}