Files
dafuweng/db/migrations/20231019090918_create_admin_users.php
2026-03-02 13:44:38 +08:00

46 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
use Phinx\Db\Adapter\MysqlAdapter;
use Phinx\Migration\AbstractMigration;
final class CreateAdminUsers 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
{
$exists = $this->hasTable('admin_users');
if (!$exists) {
$table = $this->table('admin_users', ['comment' => '系统用户表']);
$table->addColumn('username', 'string', ['limit' => 120, 'null' => false, 'default' => '', 'comment' => '用户账号'])
->addColumn('password', 'string', ['limit' => 80, 'null' => false, 'default' => '', 'comment' => '密码'])
->addColumn('nickname', 'string', ['limit' => 255, 'null' => false, 'default' => '', 'comment' => '姓名'])
->addColumn('avatar', 'string', ['limit' => 255, 'null' => false, 'default' => '', 'comment' => '头像'])
->addColumn('email', 'string', ['limit' => 50, 'null' => false, 'default' => '', 'comment' => '邮箱'])
->addColumn('phone', 'string', ['limit' => 20, 'null' => false, 'default' => '', 'comment' => '手机号'])
->addColumn('type', 'integer', ['limit' => MysqlAdapter::INT_TINY, 'null' => false, 'default' => 1, 'comment' => '1 部门 2渠道'])
->addColumn('is_super', 'integer', ['limit' => MysqlAdapter::INT_TINY, 'null' => false, 'default' => 0, 'comment' => '是否超管'])
->addColumn('status', 'integer', ['limit' => MysqlAdapter::INT_TINY, 'null' => false, 'default' => 1, 'comment' => '状态(0:禁用,1:启用)'])
->addColumn('remember_token', 'string', ['limit' => 100, 'null' => false, 'default' => '', 'comment' => '备注说明'])
->addColumn('department_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => false, 'default' => 0, 'comment' => '部门id'])
->addColumn('post', 'text', ['limit' => MysqlAdapter::TEXT_LONG, 'comment' => '岗位'])
->addColumn('created_at', 'datetime', ['comment' => '创建时间'])
->addColumn('updated_at', 'datetime', ['comment' => '更新时间'])
->addColumn('deleted_at', 'datetime', ['comment' => '删除时间'])
->addIndex(['username'], ['name' => 'uni_username', 'unique' => true])
->create();
}
}
}