37 lines
1.7 KiB
PHP
37 lines
1.7 KiB
PHP
<?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);
|
|
}
|
|
}
|