hyperf-chat/migrations/2020_11_04_152602_create_us...

47 lines
1.7 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');
2021-08-01 19:57:41 +08:00
$table->string('mobile', 11)->default('')->comment('手机号');
2020-11-04 16:47:17 +08:00
$table->string('nickname', 20)->default('')->comment('用户昵称');
$table->string('avatar', 255)->default('')->comment('用户头像地址');
2021-07-08 19:09:06 +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('用户邮箱');
2021-07-08 19:09:06 +08:00
$table->unsignedTinyInteger('is_robot')->default(0)->comment('是否机器人[0:否;1:是;]');
2020-11-04 16:47:17 +08:00
$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
2021-08-01 19:57:41 +08:00
$table->unique(['mobile'], 'uk_mobile');
2020-11-04 16:47:17 +08:00
});
$prefix = config('databases.default.prefix');
Db::statement("ALTER TABLE `{$prefix}users` comment '用户信息表'");
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('users');
}
}