Download the PHP package dweik/laravel-database-patching without Composer
On this page you can find all versions of the php package dweik/laravel-database-patching. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-database-patching
Laravel SQL-Patch
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:
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/...
:
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:
Example
Here's an example of how to create and use a patch file:
-
Create a Patch File:
-
Edit the Patch File:
- Run the Patch Files:
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.