承接 dweik/laravel-database-patching 相关项目开发

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

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

dweik/laravel-database-patching

Composer 安装命令:

composer require dweik/laravel-database-patching

包简介

Laravel database patching

README 文档

README

Managing DML (Data Manipulation Language) statements during code deployment can be challenging, especially if included in database migrations designed for DDL (Data Definition Language) operations. This package provides a solution to handle DML operations separately, ensuring smooth and error-free deployments.

Why Use Laravel SQL-Patch?

Incorporating DML statements into migrations can lead to:

  • Re-run Errors: DML statements might fail if the data already exists or conditions are not met when re-running migrations in a new setup.
  • Separation of Concerns: Keeping schema changes (DDL) and data changes (DML) separate enhances clarity and maintainability of your codebase.

Features

  • Seamless DML Management: Easily create and manage DML patches without interfering with migration files.
  • Idempotent Patches: Ensure DML operations can be safely executed multiple times.
  • Structured Deployment: Maintain a clear separation between schema changes and data changes.

Installation

Install the package using Composer:

composer require dweik/laravel-database-patching

Creating a New Patch File

To create a new patch file, use the following Artisan command. The patch file will be located in database/patches/...:

php artisan sql-patch:make SomeClassName

Add your DML code under the `handler` method in the generated patch file.

Running Patch Files

To run the new patch files, use the following command:

php artisan sql-patch

Example

Here's an example of how to create and use a patch file:

  1. Create a Patch File:
php artisan sql-patch:make UpdateUserDefaults
  1. Edit the Patch File:
// database/patches/2024_08_04_104717_UpdateUserDefaults.php
use LaravelDatabasePatching\Interfaces\SQLPatchInterface;
use \Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

class UpdateUserDefaults implements SQLPatchInterface
{
    public function handler()
    {
        // Ensure the column exists before updating
        if (Schema::hasColumn('users', 'default_column')) {
            DB::table('users')->whereNull('default_column')->update(['default_column' => 'default_value']);
        }
    }
}
  1. Run the Patch Files:
php artisan sql-patch

Best Practices

  • Idempotency: Ensure all DML operations are idempotent to avoid issues when scripts are executed multiple times.
  • Testing: Test your patches in a staging environment before deploying to production.
  • Version Control: Keep your patch files under version control to track changes and collaborate effectively.

Conclusion

The Laravel SQL-Patch package simplifies the management of DML operations during production deployments, ensuring they are handled separately from migrations. This approach minimizes errors and maintains a clean and organized codebase.

Feel free to adjust further as needed for your specific package details and requirements.

dweik/laravel-database-patching 适用场景与选型建议

dweik/laravel-database-patching 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 91 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 08 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「database」 「schema」 「command」 「migration」 「update」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 dweik/laravel-database-patching 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dweik/laravel-database-patching 我们能提供哪些服务?
定制开发 / 二次开发

基于 dweik/laravel-database-patching 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 91
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-04