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.1.0(2mo ago)091MITPHPPHP ^8.1

Since Aug 4Pushed 2mo 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 today

READMEChangelogDependencies (5)Versions (3)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

40

—

FairBetter than 86% of packages

Maintenance83

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity50

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

Every ~610 days

Total

2

Last Release

87d ago

PHP version history (2 changes)1.0.0PHP ^7.3|^8.0

1.1.0PHP ^8.1

### 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

[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M193](/packages/laravel-ai)[spatie/laravel-medialibrary

Associate files with Eloquent models

6.1k43.2M629](/packages/spatie-laravel-medialibrary)[illuminate/queue

The Illuminate Queue package.

21332.6M1.6k](/packages/illuminate-queue)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M130](/packages/roots-acorn)[itpathsolutions/dbstan

Database Standardization and Analysis Tool for Laravel

492.8k](/packages/itpathsolutions-dbstan)[erag/laravel-lang-sync-inertia

A powerful Laravel package for syncing and managing language translations across backend and Inertia.js (Vue/React/Svelte) frontends, offering effortless localization, auto-sync features, and smooth multi-language support for modern Laravel applications.

4925.3k](/packages/erag-laravel-lang-sync-inertia)

PHPackages © 2026

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