PHP code example of whirlwind-framework / mongo-migrations

1. Go to this page and download the library: Download whirlwind-framework/mongo-migrations library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

whirlwind-framework / mongo-migrations example snippets


$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'
        )
    ])
)

$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'
    )
)

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

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

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

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

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

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'
                    'lidationLevel(\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');
    }
}