2016_01_04_173148_create_admin_tables.php 4.2 KB

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