41 lines
1.8 KiB
PHP
41 lines
1.8 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Metadata pemakaian barang yang masih berada dalam penguasaan teknisi.
|
|
* Kolom status lama (active/inactive) tetap dipertahankan sebagai status
|
|
* serah-terima agar alur pengembalian yang sudah berjalan tidak berubah.
|
|
*/
|
|
class Migration_Complete_technician_item_usage extends CI_Migration
|
|
{
|
|
public function up()
|
|
{
|
|
if (!$this->db->table_exists('item_technician')) return;
|
|
|
|
$columns = array(
|
|
'usage_status' => "VARCHAR(30) NOT NULL DEFAULT 'carried' AFTER status",
|
|
'usage_date' => 'DATE NULL AFTER usage_status',
|
|
'customer_id' => 'BIGINT UNSIGNED NULL AFTER usage_date',
|
|
'usage_notes' => 'TEXT NULL AFTER customer_id',
|
|
'updated_by' => 'BIGINT UNSIGNED NULL AFTER usage_notes',
|
|
'updated_at' => 'DATETIME NULL AFTER updated_by'
|
|
);
|
|
foreach ($columns as $name => $definition) {
|
|
if (!$this->db->field_exists($name, 'item_technician')) {
|
|
$this->db->query('ALTER TABLE item_technician ADD `'.$name.'` '.$definition);
|
|
}
|
|
}
|
|
|
|
$this->db->query("UPDATE item_technician SET usage_status='carried' WHERE usage_status IS NULL OR usage_status='' OR usage_status NOT IN('carried','installed')");
|
|
$index = $this->db->query("SELECT 1 FROM information_schema.statistics WHERE table_schema=DATABASE() AND table_name='item_technician' AND index_name='idx_item_technician_usage' LIMIT 1")->row();
|
|
if (!$index) {
|
|
$this->db->query('ALTER TABLE item_technician ADD KEY idx_item_technician_usage(company_id,user_id,status,usage_status,customer_id,usage_date)');
|
|
}
|
|
}
|
|
|
|
public function down()
|
|
{
|
|
throw new RuntimeException('Gunakan backup untuk mengembalikan metadata penggunaan barang teknisi.');
|
|
}
|
|
}
|