2016_01_04_173148_create_admin_tables.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. class CreateAdminTables extends Migration
  6. {
  7. public function getConnection()
  8. {
  9. return config('database.connection') ?: config('database.default');
  10. }
  11. public function config($key)
  12. {
  13. return config('admin.'.$key);
  14. }
  15. /**
  16. * Run the migrations.
  17. *
  18. * @return void
  19. */
  20. public function up()
  21. {
  22. Schema::create($this->config('database.users_table'), function (Blueprint $table) {
  23. $table->bigIncrements('id');
  24. $table->string('username', 120)->unique();
  25. $table->string('password', 80);
  26. $table->string('name');
  27. $table->string('avatar')->nullable();
  28. $table->string('remember_token', 100)->nullable();
  29. $table->timestamps();
  30. });
  31. Schema::create($this->config('database.roles_table'), function (Blueprint $table) {
  32. $table->bigIncrements('id');
  33. $table->string('name', 50);
  34. $table->string('slug', 50)->unique();
  35. $table->timestamps();
  36. });
  37. Schema::create($this->config('database.permissions_table'), function (Blueprint $table) {
  38. $table->bigIncrements('id');
  39. $table->string('name', 50);
  40. $table->string('slug', 50)->unique();
  41. $table->string('http_method')->nullable();
  42. $table->text('http_path')->nullable();
  43. $table->integer('order')->default(0);
  44. $table->bigInteger('parent_id')->default(0);
  45. $table->timestamps();
  46. });
  47. Schema::create($this->config('database.menu_table'), function (Blueprint $table) {
  48. $table->bigIncrements('id');
  49. $table->bigInteger('parent_id')->default(0);
  50. $table->integer('order')->default(0);
  51. $table->string('title', 50);
  52. $table->string('icon', 50)->nullable();
  53. $table->string('uri', 50)->nullable();
  54. $table->timestamps();
  55. });
  56. Schema::create($this->config('database.role_users_table'), function (Blueprint $table) {
  57. $table->bigInteger('role_id');
  58. $table->bigInteger('user_id');
  59. $table->unique(['role_id', 'user_id']);
  60. $table->timestamps();
  61. });
  62. Schema::create($this->config('database.role_permissions_table'), function (Blueprint $table) {
  63. $table->bigInteger('role_id');
  64. $table->bigInteger('permission_id');
  65. $table->unique(['role_id', 'permission_id']);
  66. $table->timestamps();
  67. });
  68. Schema::create($this->config('database.role_menu_table'), function (Blueprint $table) {
  69. $table->bigInteger('role_id');
  70. $table->bigInteger('menu_id');
  71. $table->unique(['role_id', 'menu_id']);
  72. $table->timestamps();
  73. });
  74. Schema::create($this->config('database.permission_menu_table'), function (Blueprint $table) {
  75. $table->bigInteger('permission_id');
  76. $table->bigInteger('menu_id');
  77. $table->unique(['permission_id', 'menu_id']);
  78. $table->timestamps();
  79. });
  80. Schema::create($this->config('database.operation_log_table'), function (Blueprint $table) {
  81. $table->bigIncrements('id');
  82. $table->bigInteger('user_id');
  83. $table->string('path');
  84. $table->string('method', 10);
  85. $table->string('ip');
  86. $table->text('input');
  87. $table->index('user_id');
  88. $table->timestamps();
  89. });
  90. }
  91. /**
  92. * Reverse the migrations.
  93. *
  94. * @return void
  95. */
  96. public function down()
  97. {
  98. Schema::dropIfExists($this->config('database.users_table'));
  99. Schema::dropIfExists($this->config('database.roles_table'));
  100. Schema::dropIfExists($this->config('database.permissions_table'));
  101. Schema::dropIfExists($this->config('database.menu_table'));
  102. Schema::dropIfExists($this->config('database.role_users_table'));
  103. Schema::dropIfExists($this->config('database.role_permissions_table'));
  104. Schema::dropIfExists($this->config('database.role_menu_table'));
  105. Schema::dropIfExists($this->config('database.permission_menu_table'));
  106. Schema::dropIfExists($this->config('database.operation_log_table'));
  107. }
  108. }