1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- use Illuminate\Database\Migrations\Migration;
- use Illuminate\Database\Schema\Blueprint;
- use Illuminate\Support\Facades\Schema;
- return new class extends Migration {
- /**
- * Run the migrations.
- */
- public function up(): void
- {
- $tableNames = config('permission.table_names');
- if (empty($tableNames)) {
- throw new \Exception('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
- }
- Schema::create('system_menus', function (Blueprint $table) {
- $table->bigIncrements('id'); // permission id
- $table->string('name', 50)->comment('菜单名称');
- $table->tinyInteger('type')->comment('菜单类型');
- $table->integer('sort')->default(0)->comment('显示顺序');
- $table->bigInteger('parent_id')->default(0)->comment('父菜单ID');
- $table->string('path', 200)->nullable()->comment('路由地址');
- $table->string('icon', 100)->nullable()->comment('菜单图标');
- $table->string('component')->nullable()->comment('组件路径');
- $table->string('component_name')->nullable()->comment('组件名');
- $table->tinyInteger('status')->default(0)->comment('菜单状态');
- $table->tinyInteger('visible')->default(1)->comment('是否可见');
- $table->tinyInteger('keep_alive')->default(1)->comment('是否缓存');
- $table->tinyInteger('always_show')->default(1)->comment('是否总是显示');
- $table->string('creator', 64)->nullable()->comment('创建者');
- $table->string('updater', 64)->nullable()->comment('更新者');
- $table->timestamps();
- });
- Schema::create('system_role_has_menus', function (Blueprint $table) use ($tableNames) {
- $table->bigIncrements('id');
- $table->unsignedBigInteger('menu_id');
- $table->unsignedBigInteger('role_id');
- $table->foreign('menu_id')
- ->references('id')
- ->on('system_menus')
- ->onDelete('cascade');
- $table->foreign('role_id')
- ->references('id')
- ->on($tableNames['roles'])
- ->onDelete('cascade');
- $table->timestamps();
- });
- }
- /**
- * Reverse the migrations.
- */
- public function down(): void
- {
- Schema::dropIfExists('system_role_has_menus');
- Schema::dropIfExists('system_menus');
- }
- };
|