2016_01_04_173148_create_admin_tables.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.operation_log_table'), function (Blueprint $table) {
  65. $table->increments('id');
  66. $table->integer('user_id');
  67. $table->string('path');
  68. $table->string('method', 10);
  69. $table->string('ip');
  70. $table->text('input');
  71. $table->index('user_id');
  72. $table->timestamps();
  73. });
  74. }
  75. /**
  76. * Reverse the migrations.
  77. *
  78. * @return void
  79. */
  80. public function down()
  81. {
  82. $connection = config('admin.database.connection') ?: config('database.default');
  83. Schema::connection($connection)->dropIfExists(config('admin.database.users_table'));
  84. Schema::connection($connection)->dropIfExists(config('admin.database.roles_table'));
  85. Schema::connection($connection)->dropIfExists(config('admin.database.permissions_table'));
  86. Schema::connection($connection)->dropIfExists(config('admin.database.menu_table'));
  87. Schema::connection($connection)->dropIfExists(config('admin.database.user_permissions_table'));
  88. Schema::connection($connection)->dropIfExists(config('admin.database.role_users_table'));
  89. Schema::connection($connection)->dropIfExists(config('admin.database.role_permissions_table'));
  90. Schema::connection($connection)->dropIfExists(config('admin.database.operation_log_table'));
  91. }
  92. }