create_tenancy_tables.php 4.7 KB

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