Files
FendxPHP/database/migrations/2024_01_15_000001_create_users_table.php

49 lines
2.1 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
use Fendx\Database\Schema\Schema;
use Fendx\Database\Migration;
/**
* 创建用户表
*/
class CreateUsersTable extends Migration
{
public function up(): void
{
Schema::create('users', function (Schema\Table $table) {
$table->id('id')->primary()->autoIncrement();
$table->string('username', 50)->unique()->comment('用户名');
$table->string('email', 100)->unique()->comment('邮箱');
$table->string('password', 255)->comment('密码');
$table->string('nickname', 50)->nullable()->comment('昵称');
$table->string('avatar', 255)->nullable()->comment('头像');
$table->string('phone', 20)->nullable()->comment('手机号');
$table->enum('gender', ['male', 'female', 'other'])->nullable()->comment('性别');
$table->date('birthday')->nullable()->comment('生日');
$table->text('bio')->nullable()->comment('个人简介');
$table->string('status', 20)->default('active')->comment('状态: active, inactive, banned');
$table->boolean('email_verified')->default(false)->comment('邮箱是否验证');
$table->boolean('phone_verified')->default(false)->comment('手机是否验证');
$table->timestamp('email_verified_at')->nullable()->comment('邮箱验证时间');
$table->timestamp('phone_verified_at')->nullable()->comment('手机验证时间');
$table->timestamp('last_login_at')->nullable()->comment('最后登录时间');
$table->string('last_login_ip', 45)->nullable()->comment('最后登录IP');
$table->timestamp('created_at')->useCurrent()->comment('创建时间');
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate()->comment('更新时间');
// 索引
$table->index('username');
$table->index('email');
$table->index('status');
$table->index('created_at');
$table->index('last_login_at');
});
}
public function down(): void
{
Schema::dropIfExists('users');
}
}