This commit is contained in:
2021-04-13 21:01:29 -04:00
parent 5129cca099
commit 1dab43ca90
2 changed files with 83 additions and 0 deletions

38
db/seeds/Currencies.php Normal file
View File

@ -0,0 +1,38 @@
<?php
use Phinx\Seed\AbstractSeed;
class Currencies extends AbstractSeed
{
/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeders is available here:
* https://book.cakephp.org/phinx/0/en/seeding.html
*/
public function run()
{
$data = [
[
'code' => 'CLP',
'name' => 'Peso Chileno'
],
[
'code' => 'CLF',
'name' => 'Unidad de Fomento'
],
[
'code' => 'USD',
'name' => 'US Dollar'
],
[
'code' => 'BTC',
'name' => 'Bitcoin'
]
];
$this->table('currencies')->insert($data)->saveData();
}
}

45
db/seeds/Sources.php Normal file
View File

@ -0,0 +1,45 @@
<?php
use Phinx\Seed\AbstractSeed;
class Sources extends AbstractSeed
{
public function getDependencies() {
return [
'Currencies'
];
}
/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeders is available here:
* https://book.cakephp.org/phinx/0/en/seeding.html
*/
public function run()
{
$id = $this->query("SELECT id FROM currencies WHERE code = 'USD'")->fetchAll(\PDO::FETCH_ASSOC);
$data = [
[
'currency_id' => $id[0]['id'],
'url' => 'https://mindicador.cl/api/dolar/{year}',
'frecuency' => '1 DAY'
]
];
$id = $this->query("SELECT id FROM currencies WHERE code = 'CLF'")->fetchAll(\PDO::FETCH_ASSOC);
$data []= [
'currency_id' => $id[0]['id'],
'url' => 'https://mindicador.cl/api/uf/{year}',
'frecuency' => '1 DAY'
];
$id = $this->query("SELECT id FROM currencies WHERE code = 'BTC'")->fetchAll(\PDO::FETCH_ASSOC);
$data []= [
'currency_id' => $id[0]['id'],
'url' => 'https://mindicador.cl/api/bitcoin/{year}',
'frecuency' => '1 DAY'
];
$this->table('sources')->insert($data)->saveData();
}
}