我有这个Laravel迁移结构:
class CreateWarehouseProductTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('warehouse_products', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('product_id')->default(0);
$table->integer('warehouse_id');
$table->integer('free_amount')->default(0);
$table->integer('booked_amount')->default(0);
// ...
$table->timestamps();
});
}
// ...
}
我需要从仓库产品创建每日备份,为此,我需要创建一个与warehouse_products
完全相同的新表,并包含一个额外的字段作为备份日期。
是否有最佳做法?我认为是这样的:
class CreateWarehouseProductBackupTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('warehouse_product_backups', function (Blueprint $table) {
CreateWarehouseProductTable->cloneFieldsToHere();
$table->date('date_of_backup');
});
}
}
是否有类似的良好做法来克隆现有迁移中的字段?
答案 0 :(得分:0)
我找到了一个解决方案,我认为它并不优雅,但是可以正常工作:
int