first commit
This commit is contained in:
48
alter_tables.php
Normal file
48
alter_tables.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
// 加载环境变量
|
||||
if (file_exists(__DIR__ . '/.env')) {
|
||||
$dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__);
|
||||
$dotenv->load();
|
||||
}
|
||||
|
||||
$capsule = new Capsule;
|
||||
|
||||
$capsule->addConnection([
|
||||
'driver' => 'mysql',
|
||||
'host' => $_ENV['DB_HOST'] ?? '127.0.0.1',
|
||||
'port' => $_ENV['DB_PORT'] ?? '3306',
|
||||
'database' => $_ENV['DB_DATABASE'] ?? '',
|
||||
'username' => $_ENV['DB_USERNAME'] ?? '',
|
||||
'password' => $_ENV['DB_PASSWORD'] ?? '',
|
||||
'charset' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
'prefix' => '',
|
||||
]);
|
||||
|
||||
$capsule->setAsGlobal();
|
||||
$capsule->bootEloquent();
|
||||
|
||||
// 补充 roles 字段
|
||||
if (!Capsule::schema()->hasColumn('roles', 'description')) {
|
||||
Capsule::schema()->table('roles', function ($table) {
|
||||
$table->string('description', 255)->nullable()->after('name');
|
||||
});
|
||||
echo "Added 'description' to roles.\n";
|
||||
}
|
||||
|
||||
// 补充 permissions 字段
|
||||
if (!Capsule::schema()->hasColumn('permissions', 'parent_id')) {
|
||||
Capsule::schema()->table('permissions', function ($table) {
|
||||
$table->unsignedBigInteger('parent_id')->default(0)->after('id');
|
||||
$table->tinyInteger('type')->default(1)->comment('1菜单 2按钮')->after('code');
|
||||
$table->integer('sort')->default(0)->after('type');
|
||||
});
|
||||
echo "Added 'parent_id', 'type', 'sort' to permissions.\n";
|
||||
}
|
||||
|
||||
echo "Alter tables completed.\n";
|
||||
Reference in New Issue
Block a user