slovocast/app/db/migrations/20240627231445_create_transactions_table.php

50 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
/**
CREATE TABLE `transactions` (
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
channel_id INT(11) UNSIGNED NOT NULL,
code VARCHAR(255) NOT NULL,
type VARCHAR(255) NOT NULL,
total INT(11) NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
FOREIGN KEY (`channel_id`) REFERENCES channels(`id`)
);
*/
final class CreateTransactionsTable 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
{
$table = $this->table('transactions')->addTimestamps();
$table->addColumn('user_id', 'integer', [ 'null' => false ])
->addColumn('code', 'string')
->addColumn('type', 'string')
->addColumn('total', 'integer', [ 'null' => false ])
->addForeignKey('user_id', 'user');
$table->create();
}
}