create_user_tables.php.stub 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /*
  3. * This file is part of ibrand/user.
  4. *
  5. * (c) iBrand <https://www.ibrand.cc>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. use Illuminate\Support\Facades\Schema;
  11. use Illuminate\Database\Schema\Blueprint;
  12. use Illuminate\Database\Migrations\Migration;
  13. class CreateUserTables extends Migration
  14. {
  15. /**
  16. * Run the migrations.
  17. *
  18. * @return void
  19. */
  20. public function up()
  21. {
  22. $prefix = config('ibrand.app.database.prefix', 'ibrand_');
  23. if (!Schema::hasTable($prefix . 'user')) {
  24. Schema::create($prefix . 'user', function (Blueprint $table) {
  25. $table->increments('id');
  26. $table->string('name')->unique()->nullable();
  27. $table->string('nick_name')->nullable();
  28. $table->string('email')->unique()->nullable();
  29. $table->string('mobile')->unique()->nullable();
  30. $table->string('password')->nullable();
  31. $table->tinyInteger('status')->default(1);
  32. $table->string('sex')->nullable();
  33. $table->string('avatar')->nullable();
  34. $table->string('city')->nullable();
  35. $table->string('birthday')->nullable();
  36. $table->rememberToken();
  37. $table->timestamps();
  38. });
  39. }
  40. if (!Schema::hasTable($prefix . 'user_bind')) {
  41. Schema::create($prefix . 'user_bind', function (Blueprint $table) use ($prefix) {
  42. $table->increments('id');
  43. $table->unsignedInteger('user_id')->nullable(); //因为存储的时候可能还未绑定 user
  44. $table->string('type')->default('wechat'); //名称: qq, wechat, weibo,douban
  45. $table->string('app_id');
  46. $table->string('open_id')->unique();
  47. $table->string('nick_name')->nullable();
  48. $table->string('sex')->nullable();
  49. $table->string('email')->nullable();
  50. $table->string('avatar')->nullable();
  51. $table->string('city')->nullable();
  52. $table->string('province')->nullable();
  53. $table->string('country')->nullable();
  54. $table->string('language')->nullable();
  55. $table->timestamps();
  56. $table->foreign('user_id')
  57. ->references('id')
  58. ->on($prefix . 'user')
  59. ->onDelete('cascade');
  60. });
  61. }
  62. }
  63. /**
  64. * Reverse the migrations.
  65. *
  66. * @return void
  67. */
  68. public function down()
  69. {
  70. $prefix = config('ibrand.app.database.prefix', 'ibrand_');
  71. Schema::dropIfExists($prefix . 'user_bind');
  72. Schema::dropIfExists($prefix . 'user');
  73. }
  74. }