0001_01_01_000000_create_users_table.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. return new class extends Migration
  6. {
  7. /**
  8. * Run the migrations.
  9. */
  10. public function up(): void
  11. {
  12. Schema::create('users', function (Blueprint $table) {
  13. $table->comment('用户信息表');
  14. $table->id()->comment('用户ID');
  15. $table->string('name')->unique()->comment('用户账号');
  16. $table->string('email')->nullable()->comment('用户邮箱');
  17. $table->timestamp('email_verified_at')->nullable()->comment('验证邮箱');
  18. $table->string('password')->comment('用户密码');
  19. $table->string('nickname')->nullable()->comment('用户昵称');
  20. $table->string('avatar')->nullable()->comment('用户头像');
  21. $table->string('mobile')->nullable()->comment('手机号码');
  22. $table->tinyInteger('sex')->default(0)->nullable()->comment('性别');
  23. $table->string('ip_address', 45)->nullable()->comment('最后登录IP');
  24. $table->timestamp('last_activity_at')->nullable()->comment('最后登录时间');
  25. $table->text('remark')->nullable()->comment('备注');
  26. $table->tinyInteger('status')->default(0)->comment('账户状态 (0正常 1停用)');
  27. $table->bigInteger('creator')->nullable()->comment('创建者');
  28. $table->bigInteger('updater')->nullable()->comment('更新者');
  29. $table->rememberToken();
  30. $table->timestamps();
  31. });
  32. Schema::create('password_reset_tokens', function (Blueprint $table) {
  33. $table->string('name')->primary();
  34. $table->string('token');
  35. $table->timestamp('created_at')->nullable();
  36. });
  37. Schema::create('sessions', function (Blueprint $table) {
  38. $table->string('id')->primary();
  39. $table->foreignId('user_id')->nullable()->index();
  40. $table->string('ip_address', 45)->nullable();
  41. $table->text('user_agent')->nullable();
  42. $table->longText('payload');
  43. $table->integer('last_activity')->index();
  44. });
  45. }
  46. /**
  47. * Reverse the migrations.
  48. */
  49. public function down(): void
  50. {
  51. Schema::dropIfExists('users');
  52. Schema::dropIfExists('password_reset_tokens');
  53. Schema::dropIfExists('sessions');
  54. }
  55. };