2021_06_16_115448_oauth.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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')->unique()->comment('用户ID');
  17. $table->string('type', 10)->comment('登录类型');
  18. $table->string('identifier', 128)->unique()->comment('手机号/邮箱/第三方的唯一标识');
  19. $table->string('credential', 128)->comment('密码/Token凭证');
  20. $table->dateTime('created_at')->comment('创建时间');
  21. $table->dateTime('updated_at')->comment('最后更新时间');
  22. $table->foreign('user_id')->references('id')->on('user')->cascadeOnDelete();
  23. });
  24. foreach ($this->configs as $config) {
  25. Config::insert(['name' => $config]);
  26. }
  27. Schema::table('user', function (Blueprint $table) {
  28. $table->renameColumn('username', 'nickname');
  29. $table->renameColumn('email', 'username');
  30. });
  31. }
  32. /**
  33. * Reverse the migrations.
  34. *
  35. * @return void
  36. */
  37. public function down()
  38. {
  39. Schema::table('user', function (Blueprint $table) {
  40. $table->renameColumn('username', 'email');
  41. $table->renameColumn('nickname', 'username');
  42. });
  43. Config::destroy($this->configs);
  44. Schema::dropIfExists('user_oauth');
  45. }
  46. }