2016_01_04_173148_create_admin_tables.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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->timestamps();
  45. });
  46. Schema::connection($connection)->create(config('admin.database.role_users_table'), function (Blueprint $table) {
  47. $table->integer('role_id');
  48. $table->integer('user_id');
  49. $table->index(['role_id', 'user_id']);
  50. $table->timestamps();
  51. });
  52. Schema::connection($connection)->create(config('admin.database.role_permissions_table'), function (Blueprint $table) {
  53. $table->integer('role_id');
  54. $table->integer('permission_id');
  55. $table->index(['role_id', 'permission_id']);
  56. $table->timestamps();
  57. });
  58. Schema::connection($connection)->create(config('admin.database.user_permissions_table'), function (Blueprint $table) {
  59. $table->integer('user_id');
  60. $table->integer('permission_id');
  61. $table->index(['user_id', 'permission_id']);
  62. $table->timestamps();
  63. });
  64. Schema::connection($connection)->create(config('admin.database.role_menu_table'), function (Blueprint $table) {
  65. $table->integer('role_id');
  66. $table->integer('menu_id');
  67. $table->index(['role_id', 'menu_id']);
  68. $table->timestamps();
  69. });
  70. Schema::connection($connection)->create(config('admin.database.operation_log_table'), function (Blueprint $table) {
  71. $table->increments('id');
  72. $table->integer('user_id');
  73. $table->string('path');
  74. $table->string('method', 10);
  75. $table->string('ip', 15);
  76. $table->text('input');
  77. $table->index('user_id');
  78. $table->timestamps();
  79. });
  80. }
  81. /**
  82. * Reverse the migrations.
  83. *
  84. * @return void
  85. */
  86. public function down()
  87. {
  88. $connection = config('admin.database.connection') ?: config('database.default');
  89. Schema::connection($connection)->dropIfExists(config('admin.database.users_table'));
  90. Schema::connection($connection)->dropIfExists(config('admin.database.roles_table'));
  91. Schema::connection($connection)->dropIfExists(config('admin.database.permissions_table'));
  92. Schema::connection($connection)->dropIfExists(config('admin.database.menu_table'));
  93. Schema::connection($connection)->dropIfExists(config('admin.database.user_permissions_table'));
  94. Schema::connection($connection)->dropIfExists(config('admin.database.role_users_table'));
  95. Schema::connection($connection)->dropIfExists(config('admin.database.role_permissions_table'));
  96. Schema::connection($connection)->dropIfExists(config('admin.database.role_menu_table'));
  97. Schema::connection($connection)->dropIfExists(config('admin.database.operation_log_table'));
  98. }
  99. }