PHPackages                             onlinepets/laravel-conditional-migrations - 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. onlinepets/laravel-conditional-migrations

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

onlinepets/laravel-conditional-migrations
=========================================

Run your Laravel migrations only when you want them to

v1.0.0(8y ago)11.3k4MITPHPPHP ^7.0CI failing

Since Mar 28Pushed 5y ago2 watchersCompare

[ Source](https://github.com/onlinepets/laravel-conditional-migrations)[ Packagist](https://packagist.org/packages/onlinepets/laravel-conditional-migrations)[ RSS](/packages/onlinepets-laravel-conditional-migrations/feed)WikiDiscussions master Synced today

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

Deprecated:
===========

[](#deprecated)

We don't maintain this version anymore, checkout [Laravel conditional migrations](https://github.com/mll-lab/laravel-conditional-migrations) for the latest version
-------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#we-dont-maintain-this-version-anymore-checkout-laravel-conditional-migrations-for-the-latest-version)

---

Laravel Conditional Migrations
------------------------------

[](#laravel-conditional-migrations)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5941d17157cc3cc8d3facf1347254a763ed5523022a52524454e44577a75ce08/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6e6c696e65706574732f6c61726176656c2d636f6e646974696f6e616c2d6d6967726174696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/onlinepets/laravel-conditional-migrations)[![Total Downloads](https://camo.githubusercontent.com/59f8af1c358c874bf99f8c5ea71783805fb1847295a1a72c73cc063ce5c51f41/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f6e6c696e65706574732f6c61726176656c2d636f6e646974696f6e616c2d6d6967726174696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/onlinepets/laravel-conditional-migrations)[![Software License](https://camo.githubusercontent.com/6c711032aff1ca0eb6b211aa6cb3649ce7fd64a7714e1181d4bb457f9680e7cf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/6eed002d5cc62cb7d5d1fbf89f17d08286257d1b5b9500a1986462af1d9feb5d/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6f6e6c696e65706574732f6c61726176656c2d636f6e646974696f6e616c2d6d6967726174696f6e732e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/onlinepets/laravel-conditional-migrations)[![StyleCI](https://camo.githubusercontent.com/8057d653edf26f4a39dae000b51cface52b8e4725afb97b68f3edb1ce26d752c/68747470733a2f2f7374796c6563692e696f2f7265706f732f3132373130303138332f736869656c64)](https://styleci.io/repos/127100183)

This package allows you to configure migrations to run based on a condition. We expose a `ConditionalMigration` interface, which you can have your migrations implement to determine whether or not it should run.

Index
-----

[](#index)

- [Installation](#installation)
    - [Downloading](#downloading)
    - [Registering the service provider](#registering-the-service-provider)
- [Usage](#usage)
    - [Nightly cronjob](#nightly-cronjob)
- [Configuration](#configuration)
- [Contributing](#contributing)
- [License](#license)

Installation
------------

[](#installation)

You'll have to follow a couple of steps to install this package.

### Downloading

[](#downloading)

Via [composer](http://getcomposer.org):

```
$ composer require onlinepets/laravel-conditional-migrations
```

Or add the package to your dependencies in `composer.json` and run `composer update` on the command line to download the package:

```
{
    "require": {
        "onlinepets/laravel-conditional-migrations": "^1.0"
    }
}
```

### Registering the service provider

[](#registering-the-service-provider)

If you're **not** using [auto discovery](https://medium.com/@taylorotwell/package-auto-discovery-in-laravel-5-5-ea9e3ab20518), register the `\Onlinepets\ConditionalMigrations\ServiceProvider` in `config/app.php`:

```
'providers' => [
    // ...
    Onlinepets\ConditionalMigrations\ServiceProvider::class,
];
```

Usage
-----

[](#usage)

To make sure a migration only runs between 1 AM and 2 AM, implement the `ConditionalMigration`interface and its `->shouldRun()` method:

```
use Onlinepets\ConditionalMigrations\Contracts\ConditionalMigration;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Carbon;

class DoSomethingVeryIntensive extends Migration implements ConditionalMigration
{
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            //
        });
    }

    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            //
        });
    }

    public function shouldRun(): bool
    {
        return (new Carbon('1 AM'))->lessThan(now())
            && (new Carbon('2 AM'))->greaterThan(now());
    }
}
```

The code snippet above will make sure the `do_something_very_intensive` migration will be skipped unless it is executed between 1 AM and 2 AM. This can be useful if your migration does something that should not be run during the daytime, like adding an index to a table containing lots of data.

### Nightly cronjob

[](#nightly-cronjob)

To take full advantage of this package, you can schedule a task to migrate the database during the "whitelisted" times. **This package does not implement this**.

Configuration
-------------

[](#configuration)

You can optionally publish the configuration file:

```
$ php artisan vendor:publish --provider="Onlinepets\ConditionalMigrations\ServiceProvider"
```

This will create the file `config/conditional-migrations.php`, which is where you can configure whether your migrations should run, *regardless of individual configuration*:

```
return [

    'always_run' => env('APP_DEBUG', false),

];
```

You can also use a closure if you want to do more advanced calculations:

```
return [

    'always_run' => function (): bool {
        // calculate whether it should run
    },

];
```

Contributing
------------

[](#contributing)

All contributions (pull requests, issues and feature requests) are welcome. Make sure to read through the [CONTRIBUTING.md](CONTRIBUTING.md) first, though. See the [contributors page](../../graphs/contributors) for all contributors.

License
-------

[](#license)

`onlinepets/laravel-conditional-migrations` is licensed under the MIT License (MIT). Please see the [license file](LICENSE.md) for more information.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

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

3015d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/486765?v=4)[Thomas](/maintainers/thomasmoors)[@thomasmoors](https://github.com/thomasmoors)

---

Top Contributors

[![MartijnBastiaansen](https://avatars.githubusercontent.com/u/32897569?v=4)](https://github.com/MartijnBastiaansen "MartijnBastiaansen (2 commits)")[![svenluijten](https://avatars.githubusercontent.com/u/11269635?v=4)](https://github.com/svenluijten "svenluijten (1 commits)")

---

Tags

databaseeloquentlaravellaravel-packagemigrationslaraveldatabaseeloquentcronmigrationscronjob

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/onlinepets-laravel-conditional-migrations/health.svg)

```
[![Health](https://phpackages.com/badges/onlinepets-laravel-conditional-migrations/health.svg)](https://phpackages.com/packages/onlinepets-laravel-conditional-migrations)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11222.5M33](/packages/anourvalar-eloquent-serialize)[waad/laravel-model-metadata

A robust Laravel package for handling metadata with JSON casting, custom relation names, and advanced querying capabilities.

854.1k](/packages/waad-laravel-model-metadata)[ramadan/easy-model

A Laravel package for enjoyably managing database queries.

111.6k](/packages/ramadan-easy-model)

PHPackages © 2026

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