Files
accounting_dev_v2/application/migrations/20260907000200_complete_sales_document_metadata.php
T
2026-09-11 16:03:00 +07:00

16 lines
1.2 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Migration_Complete_sales_document_metadata extends CI_Migration
{
private function col($t,$c,$d){if($this->db->table_exists($t)&&!$this->db->field_exists($c,$t))$this->db->query("ALTER TABLE `$t` ADD `$c` $d");}
public function up(){
foreach(array('created_by'=>'INT NULL','created_at'=>'DATETIME NULL','submitted_by'=>'INT NULL','submitted_at'=>'DATETIME NULL','approved_by'=>'INT NULL','approved_at'=>'DATETIME NULL','rejected_by'=>'INT NULL','rejected_at'=>'DATETIME NULL','rejection_reason'=>'TEXT NULL')as$c=>$d)$this->col('invoices',$c,$d);
foreach(array('company_id'=>'BIGINT UNSIGNED NULL','updated_at'=>'DATETIME NULL')as$c=>$d)$this->col('transaction_attachments',$c,$d);
if($this->db->table_exists('transaction_attachments')&&$this->db->field_exists('company_id','transaction_attachments')){
$company=$this->db->select('id')->order_by('id')->limit(1)->get('companies')->row();
if($company)$this->db->where('company_id IS NULL',null,false)->update('transaction_attachments',array('company_id'=>$company->id));
}
}
public function down(){throw new RuntimeException('Gunakan backup database untuk rollback metadata Penjualan.');}
}