2016_01_04_173148_create_admin_tables.php 4.6 KB

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