2024_08_29_032939_create_system_menus_table.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. return new class extends Migration {
  6. /**
  7. * Run the migrations.
  8. */
  9. public function up(): void
  10. {
  11. $tableNames = config('permission.table_names');
  12. if (empty($tableNames)) {
  13. throw new \Exception('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
  14. }
  15. Schema::create('system_menus', function (Blueprint $table) {
  16. $table->bigIncrements('id'); // permission id
  17. $table->string('name', 50)->comment('菜单名称');
  18. $table->tinyInteger('type')->comment('菜单类型');
  19. $table->integer('sort')->default(0)->comment('显示顺序');
  20. $table->bigInteger('parent_id')->default(0)->comment('父菜单ID');
  21. $table->string('path', 200)->nullable()->comment('路由地址');
  22. $table->string('icon', 100)->nullable()->comment('菜单图标');
  23. $table->string('component')->nullable()->comment('组件路径');
  24. $table->string('component_name')->nullable()->comment('组件名');
  25. $table->tinyInteger('status')->default(0)->comment('菜单状态');
  26. $table->tinyInteger('visible')->default(1)->comment('是否可见');
  27. $table->tinyInteger('keep_alive')->default(1)->comment('是否缓存');
  28. $table->tinyInteger('always_show')->default(1)->comment('是否总是显示');
  29. $table->string('creator', 64)->nullable()->comment('创建者');
  30. $table->string('updater', 64)->nullable()->comment('更新者');
  31. $table->timestamps();
  32. });
  33. Schema::create('system_role_has_menus', function (Blueprint $table) use ($tableNames) {
  34. $table->bigIncrements('id');
  35. $table->unsignedBigInteger('menu_id');
  36. $table->unsignedBigInteger('role_id');
  37. $table->foreign('menu_id')
  38. ->references('id')
  39. ->on('system_menus')
  40. ->onDelete('cascade');
  41. $table->foreign('role_id')
  42. ->references('id')
  43. ->on($tableNames['roles'])
  44. ->onDelete('cascade');
  45. $table->timestamps();
  46. });
  47. }
  48. /**
  49. * Reverse the migrations.
  50. */
  51. public function down(): void
  52. {
  53. Schema::dropIfExists('system_role_has_menus');
  54. Schema::dropIfExists('system_menus');
  55. }
  56. };