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.');} }