This commit is contained in:
2026-07-12 19:21:35 +02:00
parent f2d944b117
commit 41cb412cb0
49 changed files with 3170 additions and 52 deletions
@@ -0,0 +1,36 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateReceiptItems extends Migration
{
public function up(): void
{
$this->forge->addField([
'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
'receipt_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
'name' => ['type' => 'VARCHAR', 'constraint' => 255],
'qty' => ['type' => 'DECIMAL', 'constraint' => '10,3', 'null' => true],
'amount' => ['type' => 'DECIMAL', 'constraint' => '12,2'],
'suggested_category_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true],
'chosen_category_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true],
'created_at' => ['type' => 'DATETIME', 'null' => true],
'updated_at' => ['type' => 'DATETIME', 'null' => true],
]);
$this->forge->addKey('id', true);
$this->forge->addKey('receipt_id');
// Kasacja paragonu kasuje jego pozycje.
$this->forge->addForeignKey('receipt_id', 'receipts', 'id', 'CASCADE', 'CASCADE');
// Kasacja kategorii zeruje podpowiedz/wybor (nie blokuje).
$this->forge->addForeignKey('suggested_category_id', 'categories', 'id', 'SET NULL', 'SET NULL');
$this->forge->addForeignKey('chosen_category_id', 'categories', 'id', 'SET NULL', 'SET NULL');
$this->forge->createTable('receipt_items', true, ['ENGINE' => 'InnoDB']);
}
public function down(): void
{
$this->forge->dropTable('receipt_items', true);
}
}