43 lines
1.9 KiB
PHP
43 lines
1.9 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class Migration_Extend_invoice_financial_lines extends CI_Migration
|
|
{
|
|
private function column($table,$column,$definition)
|
|
{
|
|
if($this->db->table_exists($table)&&!$this->db->field_exists($column,$table))
|
|
$this->db->query("ALTER TABLE `{$table}` ADD `{$column}` {$definition}");
|
|
}
|
|
|
|
private function index($table,$name,$columns)
|
|
{
|
|
if(!$this->db->table_exists($table))return;
|
|
foreach($this->db->query("SHOW INDEX FROM `{$table}`")->result()as$i)if($i->Key_name===$name)return;
|
|
$this->db->query("ALTER TABLE `{$table}` ADD KEY `{$name}` ({$columns})");
|
|
}
|
|
|
|
public function up()
|
|
{
|
|
if($this->db->table_exists('invoice_details')&&$this->db->field_exists('line_type','invoice_details'))
|
|
$this->db->query("ALTER TABLE `invoice_details` MODIFY `line_type` ENUM('inventory','service','loan','savings') NOT NULL DEFAULT 'inventory'");
|
|
|
|
$this->column('invoice_details','counter_account_id','INT NULL AFTER `account_id`');
|
|
$this->index('invoice_details','idx_invoice_line_counter_account','`company_id`,`counter_account_id`');
|
|
|
|
if($this->db->table_exists('invoice_line_barcodes')){
|
|
foreach($this->db->query("SHOW INDEX FROM `invoice_line_barcodes`")->result()as$i){
|
|
if($i->Key_name==='uq_invoice_line_barcode'){
|
|
$this->db->query('ALTER TABLE `invoice_line_barcodes` DROP INDEX `uq_invoice_line_barcode`');
|
|
break;
|
|
}
|
|
}
|
|
$this->db->query('ALTER TABLE `invoice_line_barcodes` ADD UNIQUE KEY `uq_invoice_line_barcode` (`invoice_detail_id`,`barcode_id`)');
|
|
}
|
|
}
|
|
|
|
public function down()
|
|
{
|
|
throw new RuntimeException('Gunakan backup database untuk rollback perluasan kategori item invoice.');
|
|
}
|
|
}
|