Files
finansePRO/app/Database/Migrations/2026-07-06-200003_CreateReceiptCategoryMap.php
T
2026-07-12 19:21:35 +02:00

29 lines
1.0 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateReceiptCategoryMap extends Migration
{
public function up(): void
{
$this->forge->addField([
'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
'item_name' => ['type' => 'VARCHAR', 'constraint' => 255],
'category_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
'updated_at' => ['type' => 'DATETIME', 'null' => true],
]);
$this->forge->addKey('id', true);
// Znormalizowana nazwa pozycji jest kluczem uczenia (jedno mapowanie na nazwe).
$this->forge->addUniqueKey('item_name');
$this->forge->addForeignKey('category_id', 'categories', 'id', 'CASCADE', 'CASCADE');
$this->forge->createTable('receipt_category_map', true, ['ENGINE' => 'InnoDB']);
}
public function down(): void
{
$this->forge->dropTable('receipt_category_map', true);
}
}