2021_06_16_115448_oauth.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. use App\Models\Config;
  3. use Illuminate\Database\Migrations\Migration;
  4. use Illuminate\Database\Schema\Blueprint;
  5. use Illuminate\Support\Facades\Schema;
  6. class Oauth extends Migration
  7. {
  8. protected $configs = [
  9. 'oauth_path',
  10. 'username_type',
  11. ];
  12. public function up()
  13. {
  14. Schema::create('user_oauth', function (Blueprint $table) {
  15. $table->increments('id');
  16. $table->unsignedInteger('user_id')->comment('用户ID');
  17. $table->string('type', 10)->comment('登录类型');
  18. $table->string('identifier', 128)->unique()->comment('手机号/邮箱/第三方的唯一标识');
  19. $table->string('credential', 128)->nullable()->comment('密码/Token凭证');
  20. $table->dateTime('created_at')->comment('创建时间');
  21. $table->dateTime('updated_at')->comment('最后更新时间');
  22. $table->unique(['user_id', 'type']);
  23. $table->foreign('user_id')->references('id')->on('user')->cascadeOnDelete();
  24. });
  25. foreach ($this->configs as $config) {
  26. Config::insert(['name' => $config]);
  27. }
  28. Schema::table('user', function (Blueprint $table) {
  29. $table->renameColumn('username', 'nickname');
  30. $table->renameColumn('email', 'username');
  31. });
  32. }
  33. /**
  34. * Reverse the migrations.
  35. *
  36. * @return void
  37. */
  38. public function down()
  39. {
  40. Schema::table('user', function (Blueprint $table) {
  41. $table->renameColumn('username', 'email');
  42. $table->renameColumn('nickname', 'username');
  43. });
  44. Config::destroy($this->configs);
  45. Schema::dropIfExists('user_oauth');
  46. }
  47. }