承接 rockero-cz/laravel-db-updates 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rockero-cz/laravel-db-updates

最新稳定版本:1.0.2

Composer 安装命令:

composer require rockero-cz/laravel-db-updates

包简介

This is my package laravel-db-updates

README 文档

README

Banner

Laravel DB Updates

Rockero Latest Version on Packagist Total Downloads Software License

In short, database updates package is used to update or fix your data in database. It works on the same principle as Laravel migrations.

Each DB update can be run only once across environments.

Installation

Install the package via composer:

composer require rockero-cz/laravel-db-updates

Publish and run migrations with:

php artisan vendor:publish --tag="db-updates-migrations"
php artisan migrate

Generating Updates

php artisan make:update update_name
return new class
{
    /**
     * Run the updates.
     */
    public function __invoke(): void
    {
        //
    }
};

Running Updates

php artisan db:update

Usage Examples

Below you can find some practical examples.

Until now, a post could only have one image, now it can have multiple ones though, so you need to transfer your post image to the separate images table:

/**
 * Run the updates.
 */
public function __invoke(): void
{
    Post::all()->each(function (Post $post) {
        $post->images()->create([
            'url' => $post->image,
            'title' => $post->title
        ]);
    });
}

Your production database had some testing data and you finally decided to delete them, so you need to delete all records older than 2023-01-01:

/**
 * Run the updates.
 */
public function __invoke(): void
{
    Post::query()
        ->where('created_at', '<', '2023-01-01')
        ->delete();

    User::query()
        ->where('created_at', '<', '2023-01-01')
        ->delete();
}

You have made some refactoring and you also renamed a state name, so you need to rename it in the database:

/**
 * Run the updates.
 */
public function __invoke(): void
{
    Order::query()
        ->where('state', 'new')
        ->update(['state' => OrderState::CREATED]);
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 3.49k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固