Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Mongodb Migrations Bundle Laravel Package

doesntmattr/mongodb-migrations-bundle

Symfony bundle that integrates the doesntmattr MongoDB Migrations library, providing configuration and tooling to run MongoDB schema/data migrations in Symfony apps. Supports PHP 5.6 via v1.x and PHP 7.1+ via v3.x.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:
    • Aligns with Laravel’s migration-first philosophy but leverages Symfony’s DI container for MongoDB migrations, offering a structured approach to schema evolution.
    • Supports container-aware migrations, enabling dependency injection (e.g., Doctrine ODM, custom services) for complex transformations.
    • Idempotent design: Tracks migration versions in a dedicated collection (migration_versions), ensuring deterministic execution.
    • Complements Laravel’s Artisan CLI (via Symfony’s console commands), enabling seamless integration into deployment pipelines.
  • Cons:
    • Symfony-centric: Assumes Symfony’s AppKernel and YAML config (e.g., config.yml), requiring Laravel-specific adaptations (e.g., config/services.php).
    • No native Laravel support: Requires manual bridging (e.g., wrapping Symfony commands in Laravel’s Console/Kernel).
    • Legacy PHP support: While PHP 7.1+ is required, Laravel’s ecosystem leans toward newer versions (8.x/9.x), which may introduce compatibility friction.

Integration Feasibility

  • Core Features:
    • Migration generation: Replace Laravel’s php artisan make:migration with mongodb:migrations:generate for MongoDB-specific changes.
    • Version control: Use mongodb:migrations:status to audit migration history (similar to Laravel’s migrate:status).
    • Rollbacks: Limited native support (vs. Laravel’s migrate:rollback); manual version deletion (mongodb:migrations:version --delete) may be needed.
  • Challenges:
    • Doctrine ODM Dependency: If using MongoDB with Laravel, ensure Doctrine MongoDB ODM is installed (doctrine/mongodb-odm-bundle equivalent).
    • Configuration Overhead: Symfony’s config.yml must be translated to Laravel’s config/mongodb-migrations.php.
    • Artisan Command Wrapping: Symfony commands must be exposed via Laravel’s Console/Kernel::commands() or a custom facade.

Technical Risk

  • High:
    • Symfony-Laravel Integration Risk: Poorly abstracted Symfony dependencies (e.g., ContainerAwareInterface) may require significant refactoring.
    • Migration Rollback Gaps: Lack of built-in down() methods (vs. Laravel’s reversible migrations) could complicate disaster recovery.
    • Documentation Gaps: Limited Laravel-specific guidance; reliance on Symfony’s ecosystem (e.g., ManagerRegistry for Doctrine ODM).
  • Mitigation:
    • Wrapper Layer: Create a Laravel service provider to normalize Symfony commands and configurations.
    • Testing: Validate migration idempotency and rollback scenarios in staging.
    • Fallback: Use raw mongodb-migrations library if bundle integration proves too cumbersome.

Key Questions

  1. Is Symfony’s DI container a hard requirement?
    • If not, can the bundle be stripped down to use Laravel’s container directly?
  2. How will rollbacks be handled?
    • Will manual version deletion suffice, or must custom down() logic be implemented?
  3. What’s the MongoDB driver strategy?
    • Will Laravel’s native MongoDB driver or Doctrine ODM be used? (Affects Database class compatibility.)
  4. Deployment Pipeline Impact:
    • How will this integrate with Laravel’s migrate Artisan command (e.g., chaining or replacement)?
  5. Performance:
    • Are cursor timeouts (socketTimeoutMs) critical for large collections? If so, how will they be configured?

Integration Approach

Stack Fit

  • Laravel Compatibility:

    • Core: Works with Laravel 8+/9+ (PHP 7.4+) if using Symfony’s ^3.0 branch.
    • Dependencies:
      • Requires Doctrine MongoDB ODM (doctrine/mongodb-odm) for ContainerAwareInterface support.
      • Conflicts with Laravel’s native MongoDB driver unless abstracted.
    • Alternatives:
      • Use the underlying mongodb-migrations library directly for lighter integration.
      • Explore Laravel-specific MongoDB migration packages (e.g., spatie/laravel-mongodb).
  • Symfony vs. Laravel:

    • Symfony Components: Leverage Console/Command and DependencyInjection via Laravel’s service container.
    • Configuration: Replace config.yml with Laravel’s config/mongodb-migrations.php:
      return [
          'collection_name' => 'migration_versions',
          'database_name' => env('DB_DATABASE'),
          'dir_name' => database_path('migrations/mongodb'),
          'namespace' => 'Database\\Migrations\\MongoDB',
      ];
      

Migration Path

  1. Phase 1: Proof of Concept

    • Install the bundle in a sandbox project:
      composer require doesntmattr/mongodb-migrations-bundle "^3.0"
      
    • Create a Laravel service provider to register Symfony commands:
      // app/Providers/MongoDBMigrationsServiceProvider.php
      namespace App\Providers;
      use AntiMattr\Bundle\MongoDBMigrationsBundle\MongoDBMigrationsBundle;
      use Illuminate\Support\ServiceProvider;
      
      class MongoDBMigrationsServiceProvider extends ServiceProvider {
          public function register() {
              $this->app->register(MongoDBMigrationsBundle::class);
          }
      }
      
    • Publish config and migrations:
      php artisan vendor:publish --provider="AntiMattr\Bundle\MongoDBMigrationsBundle\MongoDBMigrationsBundle"
      
  2. Phase 2: Command Integration

    • Expose Symfony commands in app/Console/Kernel.php:
      protected $commands = [
          \AntiMattr\Bundle\MongoDBMigrationsBundle\Command\MigrateCommand::class,
          // ... other commands
      ];
      
    • Create aliases for Artisan:
      php artisan mongodb:migrations:generate --name=add_index_to_users
      
  3. Phase 3: Rollback Strategy

    • Implement custom down() methods in migrations or use manual version deletion:
      php artisan mongodb:migrations:version --delete 20231001000000
      

Compatibility

  • Doctrine ODM:
    • Ensure doctrine/mongodb-odm is installed and configured in config/packages/doctrine_mongodb_odm.php.
    • Verify Database class compatibility (Symfony’s MongoDB\Database vs. Laravel’s MongoDB\Client).
  • Artisan:
    • Symfony commands must extend Laravel’s Illuminate\Console\Command or be wrapped in a facade.
  • Environment:
    • Test with Laravel’s .env variables (e.g., DB_DATABASE, DB_MONGODB_URI).

Sequencing

  1. Initial Setup:
    • Install dependencies → Configure bundle → Publish assets.
  2. Migration Workflow:
    • Generate migrations → Test locally → Deploy with mongodb:migrations:migrate.
  3. Rollback:
    • Manual version deletion or custom down() logic.
  4. Long-term:
    • Monitor for Symfony deprecations (e.g., ManagerRegistry changes in Doctrine ODM).

Operational Impact

Maintenance

  • Pros:
    • Version Tracking: Centralized migration_versions collection simplifies auditing.
    • Container Awareness: Easier to inject services (e.g., repositories, factories) into migrations.
  • Cons:
    • Symfony Dependencies: Future Symfony updates may require bundle patches.
    • Lack of Laravel Tooling: No native integration with Laravel’s Schema builder or migrate command.
  • Mitigation:
    • Fork and Maintain: Customize the bundle for Laravel-specific needs.
    • Documentation: Maintain a MONGODB_MIGRATIONS.md guide for the team.

Support

  • Debugging:
    • Use mongodb:migrations:status to diagnose failed migrations.
    • Check Symfony’s Database object for MongoDB errors (e.g., duplicate keys).
  • Rollback Complexity:
    • Manual version deletion may require downtime; automate with scripts if critical.
  • Community:
    • Limited Laravel-specific support; rely on Symfony’s issue tracker or fork contributions.

Scaling

  • Performance:
    • Cursor Timeouts: Configure socketTimeoutMs for large collections (e.g., ['socketTimeoutMs' => 30000]).
    • Batch Processing: Split migrations into smaller batches to avoid locks.
  • Concurrency:
    • MongoDB migrations are not thread-safe by default; ensure single-process execution during deployments.
  • CI/CD:
    • Integrate mongodb:migrations:migrate into deployment pipelines (e.g., GitHub Actions):
      - run: php artisan mongodb:migrations:migrate --env=production --force
      

Failure Modes

| Scenario | Impact | Mitigation | |----------------------------|-------------------------------------

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui