[FEATURE] 数据库迁移,迁移文件类名优化
linjiangl opened this issue · comments
项目如果迭代还快,添加字段不是很方便
执行如下命令两次,生成类为 AddColumnsToUsersTable
, 文件为 2024_06_04_143919_add_columns_to_users_table.php
,第二次生成失败,因为类名不能重复。
/hyperf-skeleton/services # bin/hyperf.php gen:migration add_columns_to_users_table
[INFO] Created Migration: 2024_06_04_143919_add_columns_to_users_table
/hyperf-skeleton/services # bin/hyperf.php gen:migration add_columns_to_users_table
[ERROR] Created Migration: A AddColumnsToUsersTable class already exists.
/hyperf-skeleton/services #
<?php
use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;
class AddColumnsToUsersTable extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
//
});
}
.....
希望改进,不受类名影响,如laravel 10
执行命令
/www/server # php artisan make:migration add_columns_to_users_table
INFO Created migration [2024_06_04_144531_add_columns_to_users_table].
/www/server # php artisan make:migration add_columns_to_users_table
INFO Created migration [2024_06_04_144536_add_columns_to_users_table].
/www/server #
生成的文件如下
2024_06_04_144531_add_columns_to_users_table.php
2024_06_04_144536_add_columns_to_users_table.php
上述两个文件内容如下
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
//
});
}
.......