Files
alrahma_sunday_school/app/Database/Migrations/2026-07-19-000800_CreateInventoryReceiptOperations.php
root a30c1398a1
Tests / PHPUnit (push) Failing after 1m21s
fix financials
2026-07-18 22:57:40 -04:00

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