PHPackages                             dweik/laravel-database-patching - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. dweik/laravel-database-patching

ActiveLibrary[Database &amp; ORM](/categories/database)

dweik/laravel-database-patching
===============================

Laravel database patching

1.0.0(1y ago)06MITPHPPHP ^7.3|^8.0

Since Aug 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/asd4abyd/laravel-database-patching)[ Packagist](https://packagist.org/packages/dweik/laravel-database-patching)[ RSS](/packages/dweik-laravel-database-patching/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Laravel SQL-Patch
=================

[](#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?
--------------------------

[](#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
--------

[](#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
------------

[](#installation)

Install the package using Composer:

```
composer require dweik/laravel-database-patching
```

Creating a New Patch File
-------------------------

[](#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
-------------------

[](#running-patch-files)

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

```
php artisan sql-patch
```

Example
-------

[](#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
```

2. **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']);
        }
    }
}
```

3. **Run the Patch Files:**

```
php artisan sql-patch
```

Best Practices
--------------

[](#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
----------

[](#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.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

652d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15715732?v=4)[Abdelqader Osama Aldweik](/maintainers/asd4abyd)[@asd4abyd](https://github.com/asd4abyd)

---

Tags

laravelschemamigrationdatabaseartisancommandseedingseedupdatingupdatedeleteaddinsertpatchingmodifyaddingincremantalinsertingdeletingmodifying

### Embed Badge

![Health badge](/badges/dweik-laravel-database-patching/health.svg)

```
[![Health](https://phpackages.com/badges/dweik-laravel-database-patching/health.svg)](https://phpackages.com/packages/dweik-laravel-database-patching)
```

###  Alternatives

[nwidart/db-exporter

Export your database quickly and easily as a Laravel Migration and all the data as a Seeder class.

37839.1k](/packages/nwidart-db-exporter)[elimuswift/db-exporter

Export your database quickly and easily as a Laravel Migration and all the data as a Seeder class.

364.7k](/packages/elimuswift-db-exporter)[dragon-code/laravel-data-dumper

Adding data from certain tables when executing the `php artisan schema:dump` console command

3418.6k](/packages/dragon-code-laravel-data-dumper)[jlapp/smart-seeder

Smart Seeder adds the same methology to seeding that is currently used with migrations in order to let you seed in batches, seed to production databases or other environments, and to rerun seeds without wiping out your data.

1903.1k](/packages/jlapp-smart-seeder)[eighty8/laravel-seeder

Versioned, environment-based Seeders in Laravel

1857.1k](/packages/eighty8-laravel-seeder)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
