55 lines
2.8 KiB
PHP
55 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Database\Migrations;
|
|
|
|
use CodeIgniter\Database\Migration;
|
|
|
|
class CreateInventoryReceiptOperations extends Migration
|
|
{
|
|
public function up()
|
|
{
|
|
if (!$this->db->tableExists('inventory_receipt_operations')) {
|
|
$this->forge->addField([
|
|
'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
|
|
'idempotency_key' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => false],
|
|
'purchase_order_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => false],
|
|
'request_fingerprint_hash' => ['type' => 'CHAR', 'constraint' => 64, 'null' => false],
|
|
'status' => ['type' => 'VARCHAR', 'constraint' => 30, 'null' => false],
|
|
'actor_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true],
|
|
'created_at' => ['type' => 'DATETIME', 'null' => false],
|
|
'updated_at' => ['type' => 'DATETIME', 'null' => false],
|
|
]);
|
|
$this->forge->addKey('id', true);
|
|
$this->forge->addUniqueKey('idempotency_key', 'uniq_inventory_receipt_operation_key');
|
|
$this->forge->createTable('inventory_receipt_operations', true);
|
|
}
|
|
|
|
if (!$this->db->tableExists('inventory_receipt_lines')) {
|
|
$this->forge->addField([
|
|
'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
|
|
'operation_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => false],
|
|
'purchase_order_item_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => false],
|
|
'quantity' => ['type' => 'INT', 'constraint' => 11, 'null' => false],
|
|
'movement_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true],
|
|
'reversal_movement_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true],
|
|
'reversed_quantity' => ['type' => 'INT', 'constraint' => 11, 'null' => false, 'default' => 0],
|
|
'created_at' => ['type' => 'DATETIME', 'null' => false],
|
|
]);
|
|
$this->forge->addKey('id', true);
|
|
$this->forge->addKey('operation_id');
|
|
$this->forge->addKey('purchase_order_item_id');
|
|
$this->forge->createTable('inventory_receipt_lines', true);
|
|
}
|
|
}
|
|
|
|
public function down()
|
|
{
|
|
if ($this->db->tableExists('inventory_receipt_lines')) {
|
|
$this->forge->dropTable('inventory_receipt_lines', true);
|
|
}
|
|
if ($this->db->tableExists('inventory_receipt_operations')) {
|
|
$this->forge->dropTable('inventory_receipt_operations', true);
|
|
}
|
|
}
|
|
}
|