hyperf-chat/migrations/2020_11_04_152602_create_us...

46 lines
1.6 KiB
PHP
Raw Normal View History

2020-11-04 16:47:17 +08:00
<?php
use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;
use Hyperf\DbConnection\Db;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->unsignedInteger('id', true)->comment('用户ID');
$table->string('mobile', 11)->default('')->unique()->comment('手机号');
$table->string('nickname', 20)->default('')->comment('用户昵称');
$table->string('avatar', 255)->default('')->comment('用户头像地址');
2021-07-05 21:52:44 +08:00
$table->unsignedTinyInteger('gender')->default(0)->comment('用户性别[0:未知;1:男;2:女]');
2020-11-04 16:47:17 +08:00
$table->string('password', 255)->default('')->comment('用户密码');
$table->string('motto', 100)->default('')->comment('用户座右铭');
$table->string('email', 30)->default('')->comment('用户邮箱');
$table->dateTime('created_at')->nullable()->comment('注册时间');
2021-07-05 21:52:44 +08:00
$table->dateTime('updated_at')->nullable()->comment('更新时间');
2020-11-04 16:47:17 +08:00
2021-07-05 21:52:44 +08:00
$table->charset = 'utf8';
2020-11-04 16:47:17 +08:00
$table->collation = 'utf8_general_ci';
2021-07-05 21:52:44 +08:00
$table->engine = 'InnoDB';
2020-11-04 16:47:17 +08:00
$table->unique(['mobile'], 'idx_mobile');
});
$prefix = config('databases.default.prefix');
Db::statement("ALTER TABLE `{$prefix}users` comment '用户信息表'");
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('users');
}
}