74 lines
2.4 KiB
PHP
74 lines
2.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use Phinx\Migration\AbstractMigration;
|
|
|
|
final class CreateTables extends AbstractMigration
|
|
{
|
|
/**
|
|
* Change Method.
|
|
*
|
|
* Write your reversible migrations using this method.
|
|
*
|
|
* More information on writing migrations is available here:
|
|
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
|
*
|
|
* Remember to call "create()" or "update()" and NOT "save()" when working
|
|
* with the Table class.
|
|
*/
|
|
public function change(): void
|
|
{
|
|
$this->table('coins')
|
|
->addColumn('identifier', 'string')
|
|
->addColumn('code', 'string', ['limit' => 5])
|
|
->addColumn('name', 'string')
|
|
->addColumn('prefix', 'string', ['default' => ''])
|
|
->addColumn('suffix', 'string', ['default' => ''])
|
|
->addColumn('decimals', 'integer', ['default' => 0])
|
|
->addColumn('ref_url', 'text', ['default' => ''])
|
|
->create();
|
|
|
|
$this->table('locations')
|
|
->addColumn('name', 'string')
|
|
->addColumn('description', 'string')
|
|
->create();
|
|
|
|
$cascade = ['update' => 'CASCADE', 'delete' => 'CASCADE'];
|
|
|
|
$this->table('wallets')
|
|
->addColumn('name', 'string')
|
|
->addColumn('location_id', 'integer')
|
|
->addForeignKey('location_id', 'locations', 'id', $cascade)
|
|
->addColumn('public_address', 'string')
|
|
->create();
|
|
|
|
$this->table('values')
|
|
->addColumn('date_time', 'datetime')
|
|
->addColumn('coin_id', 'integer')
|
|
->addForeignKey('coin_id', 'coins', 'id', $cascade)
|
|
->addColumn('value', 'double')
|
|
->addColumn('unit_id', 'integer')
|
|
->addForeignKey('unit_id', 'coins', 'id', $cascade)
|
|
->create();
|
|
|
|
$this->table('transactions')
|
|
->addColumn('date_time', 'datetime')
|
|
->addColumn('coin_id', 'integer')
|
|
->addForeignKey('coin_id', 'coins', 'id', $cascade)
|
|
->addColumn('wallet_id', 'integer')
|
|
->addForeignKey('wallet_id', 'wallets', 'id', $cascade)
|
|
->addColumn('amount', 'double')
|
|
->addColumn('value', 'double')
|
|
->addColumn('unit_id', 'integer')
|
|
->addForeignKey('unit_id', 'coins', 'id', $cascade)
|
|
->create();
|
|
|
|
$this->table('coin_registers')
|
|
->addColumn('type', 'integer')
|
|
->addColumn('coin_id', 'integer')
|
|
->addForeignKey('coin_id', 'coins', 'id')
|
|
->addColumn('date_time', 'datetime')
|
|
->create();
|
|
}
|
|
}
|