51 lines
1.9 KiB
PHP
51 lines
1.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 20260904071635_users.php
|
|
*
|
|
* Author: Funky Waddle
|
|
* Date: 2026-09-04
|
|
*
|
|
* Purpose: Migration that creates the `users` table storing user account records.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Phinx\Migration\AbstractMigration;
|
|
|
|
final class Users 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('users');
|
|
$table->addColumn('username', 'string', ['limit' => 255, 'null'=> false])
|
|
->addColumn('password', 'string', ['limit' => 255, 'null' => false])
|
|
->addColumn('f_name', 'string', ['limit' => 255, 'null' => false])
|
|
->addColumn('l_name', 'string', ['limit' => 255, 'null' => true])
|
|
->addColumn('email', 'string', ['limit' => 255, 'null' => false])
|
|
->addColumn('avatar', 'string', ['limit' => 255, 'null' => true])
|
|
->addColumn('failed_login_attempts', 'integer', ['null' => false, 'default' => 0])
|
|
->addColumn('locked_until', 'datetime', ['null' => true])
|
|
->addColumn('created_at', 'datetime', ['null' => false, 'default'=>"CURRENT_TIMESTAMP"])
|
|
->addColumn('created_by', 'integer', ['null' => false])
|
|
->addColumn('updated_at', 'datetime', ['null' => true])
|
|
->addColumn('updated_by', 'integer', ['null' => true])
|
|
->addForeignKey('created_by', 'users','id')
|
|
->addForeignKey('updated_by', 'users','id')
|
|
->addIndex('username', ['unique' => true])
|
|
->addIndex('email', ['unique' => true])
|
|
->create();
|
|
}
|
|
}
|