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:
- Create a Patch File:
php artisan sql-patch:make UpdateUserDefaults
- 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']); } } }
- 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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dweik/laravel-database-patching 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
A Wrapper for exec and it's results
Symfony bundle to monitor and execute commands
Store your language lines in the database, yaml or other sources
Extension for Opis JSON Schema
Shell command module for PHP.
统计信息
- 总下载量: 91
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-04