2016_01_04_173148_create_admin_tables.php 4.4 KB

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