35 lines
1.3 KiB
PHP
35 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Database\Migrations;
|
|
|
|
use CodeIgniter\Database\Migration;
|
|
|
|
class CreateOperations extends Migration
|
|
{
|
|
public function up(): void
|
|
{
|
|
$this->forge->addField([
|
|
'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
|
|
'date' => ['type' => 'DATE'],
|
|
'amount' => ['type' => 'DECIMAL', 'constraint' => '12,2'],
|
|
'type' => ['type' => 'ENUM', 'constraint' => ['income', 'expense']],
|
|
'category_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true],
|
|
'description' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
|
|
'created_at' => ['type' => 'DATETIME', 'null' => true],
|
|
'updated_at' => ['type' => 'DATETIME', 'null' => true],
|
|
]);
|
|
$this->forge->addKey('id', true);
|
|
$this->forge->addKey('date');
|
|
$this->forge->addKey('category_id');
|
|
$this->forge->addKey('type');
|
|
// Usuniecie kategorii -> operacje dostaja category_id = NULL
|
|
$this->forge->addForeignKey('category_id', 'categories', 'id', 'CASCADE', 'SET NULL');
|
|
$this->forge->createTable('operations', true, ['ENGINE' => 'InnoDB']);
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
$this->forge->dropTable('operations', true);
|
|
}
|
|
}
|