PHPackages                             whirlwind-framework/mongo-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. [Framework](/categories/framework)
4. /
5. whirlwind-framework/mongo-migrations

ActiveLibrary[Framework](/categories/framework)

whirlwind-framework/mongo-migrations
====================================

MongoDB migration tool implementation for Whirlwind framework

v0.0.2(2y ago)1257BSD-3-ClausePHPPHP &gt;=8.0

Since May 23Pushed 2y ago1 watchersCompare

[ Source](https://github.com/whirlwind-framework/mongo-migrations)[ Packagist](https://packagist.org/packages/whirlwind-framework/mongo-migrations)[ RSS](/packages/whirlwind-framework-mongo-migrations/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (4)Used By (0)

Mongo migrations
================

[](#mongo-migrations)

MongoDB's migration tool

Implementation notes
--------------------

[](#implementation-notes)

1. Bind MigrationPaths dependencies (paths to all your migration folders).

```
$container->add(
    \Whirlwind\MigrationCore\Config\MigrationPaths::class,
    fn (): \Whirlwind\MigrationCore\Config\MigrationPaths => new \Whirlwind\MigrationCore\Config\MigrationPaths([
        new \Whirlwind\MigrationCore\Config\MigrationPath(
            '/path/to/migrations/folder',
            'Your\\Migration\\Namespace'
        )
    ])
)
```

2. In case of using your own migration template file you have to bind `Config` dependency.

```
$container->add(
    Whirlwind\MigrationCore\Config\Config::class,
    fn () \Whirlwind\MigrationCore\Config\Config::class => new \Whirlwind\MigrationCore\Config\Config(
        $container->get(\Whirlwind\MigrationCore\Config\MigrationPaths::class),
        '/path/to/your/migration/template'
    )
)
```

3. Register `MongoMigrationServiceProvider` for your console application.

```
$container->addServiceProvider(new \WhirlwindFramework\MongoMigrations\MongoMigrationServiceProvider())
```

Commands
--------

[](#commands)

After registering `MongoMigrationServiceProvider` you have ability to manage your database migrations by console commands.

### Create migration

[](#create-migration)

Run this command for creating new migration file.

```
php /path/to/console/executable migrate:create MyMigration
```

The command require migration file name as the first argument. If you would like to specify migration path you can use option `--path=/my/migration/path`. Pay attention that such path must be registered in `MigrationPaths` dependency.

### Install migration

[](#install-migration)

The command will help you to install migrations.

```
php /path/to/console/executable migrate:install
```

You can control amount of migration that will be installed in your system by the limitation with the first argument. The value must be integer &gt;= 0. By default, all migrations are installed.

### Rollback migration

[](#rollback-migration)

Rollback command helps to cancel changes made by migrations

```
php /path/to/console/executable migrate:rollback
```

The last migration will be rollback in case of running the command without arguments. You can specify amount of migrations for rollback by specifying limit with the first argument. Option `--all` will help you to rollback all migrations.

### Status

[](#status)

If you would like to see which migrations have run thus far, you may use the `migrate:status` command

```
php /path/to/console/executable migrate:status
```

The output will show you 10 last migrations that was applied. You can specify limit with the first argument or with the option `--all`.

Migration API
-------------

[](#migration-api)

`Migration` has a set of useful methods for managing migration process.

```
class MyMigration111 extends \Whirlwind\MigrationCore\Migration
{
    public function up(): void {
        $this->createIfNotExists('orders', static function (\WhirlwindFramework\MongoMigrations\Blueprint $b) {
            $b->setCapped(true);
            $b->setMax(100);
            $b->setSize(500);
            $b->setCollation([
                'locale' => 'en',
                'strength' => 1,
            ]);
            $b->setValidator([
                '$jsonSchema' => [
                    'bsonType' => 'object'
                    'required' => ['name', 'year'],
                    'properties' => [
                        'name' => [
                            'bsonType' => 'string',
                        ],
                        'year' => [
                            'bsonType' => 'int',
                            'minimum' => 1990,
                            'maximum' => 3017,
                        ]
                    ]
                ]
            ]);
            $b->setValidationLevel(\WhirlwindFramework\MongoMigrations\Blueprint::VALIDATION_LEVEL_STRICT);
            $b->setValidationLevel(\WhirlwindFramework\MongoMigrations\Blueprint::VALIDATION_ACTION_ERROR);
        });

        $this->modify('orders', static function (\WhirlwindFramework\MongoMigrations\Blueprint $b) {
            $b->createIndex(['year']);

            $b->setOption('unique', true);
            $b->createIndex(['name']);
        });
    }

    public function down(): void {
        $this->modify('orders', function (\WhirlwindFramework\MongoMigrations\Blueprint $b) {
            $b->dropAllIndexes();
        });

        $this->dropIfExists('orders');
    }
}
```

- `create($collection, $callback)` - used for creating new collection. In `callback` you can specify additional options that will be used during creation.
- `createIfNotExists($collection, $callback)` - works as `create`, but in case of collection existence it skips creation
- `modify($collection, $callback)` - used for modifying collection. In `callback` you can specify additional options and make extra operations such as renaming collection or creating new indexes. Pay attention if you require different options for different commands use `modify` method as much as need.
- `drop($collection)` - delete the whole collection
- `dropIfExists($collection)` - same as `delete`, but checks if the collection exist.

### Blueprint Methods

[](#blueprint-methods)

- `create(callable)` - used for configuring creation process.
- `setCapped(bool)` - set `capped` option.
- `setSize(int)` - set `size` option for capped collection.
- `setValidator(array)` - set `validator` option for collection.
- `setValidationLevel(string)` - set `validatorLevel` option for collection. Possible values are `Blueprint::VALIDATION_LEVEL_OFF``Blueprint::VALIDATION_LEVEL_STRICT`, `Blueprint::VALIDATION_LEVEL_MODERATE`.
- `setValidationAction(string)` - set `validationAction` option for collection. Possible values are `Blueprint::VALIDATION_ACTION_WARN`, `Blueprint::VALIDATION_ACTION_ERROR`.
- `setCollation(array)` - set `collatiob` option for collection. Check MongoDB official documentation for more information.
- `setOption(string, mixed)` - set any option by its name.
- `drop()` - remove the whole collection.
- `dropIfExists()` - remove the whole collection if it exists.
- `createIfNotExists(callable)` - configure creation process for collection if it is not exists.
- `createIndex(array, ?string)` - create new index for `keys` with `name`.
- `dropIndex(string)` - delete index by name.
- `dropAllIndexes()` - delete all collection indexes.
- `renameCollection(string)` - rename collection.
- `insert(array)` - insert new document.
- `batchInsert(array)` - insert multiple documents.
- `update(array, array)` - update documents by criteria with new data.
- `delete(array)` - delete documents by criteria.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 84.6% 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

Every ~34 days

Total

2

Last Release

1054d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a703c1aca573c9decd6f315c7bf25ae11e8e63120318c97c6ce4819133080ac8?d=identicon)[Indigerd](/maintainers/Indigerd)

---

Top Contributors

[![geckoboom](https://avatars.githubusercontent.com/u/41550729?v=4)](https://github.com/geckoboom "geckoboom (11 commits)")[![Indigerd](https://avatars.githubusercontent.com/u/2143512?v=4)](https://github.com/Indigerd "Indigerd (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/whirlwind-framework-mongo-migrations/health.svg)

```
[![Health](https://phpackages.com/badges/whirlwind-framework-mongo-migrations/health.svg)](https://phpackages.com/packages/whirlwind-framework-mongo-migrations)
```

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[cakephp/core

CakePHP Framework Core classes

6026.8M39](/packages/cakephp-core)

PHPackages © 2026

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