first commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Database\Seeds;
|
||||
|
||||
use CodeIgniter\Database\Seeder;
|
||||
|
||||
class DefaultCategoriesSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$now = date('Y-m-d H:i:s');
|
||||
|
||||
$rows = [
|
||||
// Przychody
|
||||
['name' => 'Wynagrodzenie', 'type' => 'income', 'parent_id' => null],
|
||||
['name' => 'Premia', 'type' => 'income', 'parent_id' => null],
|
||||
['name' => 'Inne przychody', 'type' => 'income', 'parent_id' => null],
|
||||
// Wydatki
|
||||
['name' => 'Mieszkanie', 'type' => 'expense', 'parent_id' => null],
|
||||
['name' => 'Jedzenie', 'type' => 'expense', 'parent_id' => null],
|
||||
['name' => 'Transport', 'type' => 'expense', 'parent_id' => null],
|
||||
['name' => 'Rozrywka', 'type' => 'expense', 'parent_id' => null],
|
||||
['name' => 'Zdrowie', 'type' => 'expense', 'parent_id' => null],
|
||||
['name' => 'Inne wydatki', 'type' => 'expense', 'parent_id' => null],
|
||||
];
|
||||
|
||||
foreach ($rows as &$r) {
|
||||
$r['created_at'] = $now;
|
||||
$r['updated_at'] = $now;
|
||||
}
|
||||
|
||||
// Nie duplikuj, jesli seeder juz raz przeszedl
|
||||
if ((int) $this->db->table('categories')->countAllResults() === 0) {
|
||||
$this->db->table('categories')->insertBatch($rows);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Database\Seeds;
|
||||
|
||||
use CodeIgniter\Database\Seeder;
|
||||
|
||||
class DefaultInstrumentsSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$names = ['Obligacje', 'ETF'];
|
||||
|
||||
foreach ($names as $name) {
|
||||
// Idempotentnie: pomin instrument, ktory juz istnieje
|
||||
$exists = (int) $this->db->table('inv_instruments')->where('name', $name)->countAllResults();
|
||||
if ($exists === 0) {
|
||||
$this->db->table('inv_instruments')->insert([
|
||||
'name' => $name,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user