doesntmattr/mongodb-migrations
Laravel package for running MongoDB database migrations. Provides migration commands and structure similar to Laravel’s SQL migrations, helping you version and deploy MongoDB schema/index changes safely across environments.
php artisan migrate). Requires custom workflows or wrapper scripts.mongodb/mongodb PHP extension (v1.0+). Compatibility with Laravel’s PHP version (8.0+) is unverified (last release predates Laravel 8).artisan commands. Migrations must be triggered via custom scripts or event listeners, adding friction.| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Deprecated Package | High | Fork/maintain or replace with jenssegers/laravel-mongodb (if Eloquent is acceptable). |
| No Laravel Ecosystem Sync | Medium | Build wrapper classes to bridge with Laravel’s Migrator facade. |
| Data Migration Safety | High | Implement pre-migration backups and dry-run modes. |
| Concurrency Issues | Medium | Use MongoDB’s write concern and transactions (v4.0+) to handle parallel migrations. |
| License Compliance | Low | MIT license is permissive; no legal risk. |
Why MongoDB Migrations?
Laravel Integration Depth
artisan or external scripts?Team Expertise
Alternatives
mongosh) may suffice.go-migrate) for complex workflows.mongodb/mongodb PHP extension (v1.0+).Assessment Phase:
Tooling Setup:
mongodb/mongodb extension:
pecl install mongodb
composer require doesntmattr/mongodb-migrations
// app/Console/Commands/RunMongoMigrations.php
use DoesnTMattr\MongoDBMigrations\Migrator;
class RunMongoMigrations extends Command {
protected $signature = 'mongo:migrate';
public function handle() {
$migrator = new Migrator('mongodb://user:pass@host:port');
$migrator->migrate();
}
}
Migration Workflow:
createCollection/addIndex methods.CI/CD Integration:
| Component | Compatibility Notes |
|---|---|
| Laravel Version | Tested on Laravel 5.x (last release). May need polyfills for Laravel 8+ (e.g., PSR-15). |
| MongoDB Version | Requires MongoDB 3.6+ (for migrations API). Test with your cluster version. |
| PHP Version | PHP 7.2–7.4 (last release). Laravel 8+ uses PHP 8.0+; expect deprecation warnings. |
| Operating Systems | Cross-platform, but Windows MongoDB drivers may need extra config. |
Pre-Migration:
mongodump --collection=users --db=mydb.Migration Execution:
php artisan down --message="MongoDB migrations in progress"
Post-Migration:
var_dump() or custom logging.BSONError, WriteConcern, etc.rollback method (if reversible).mongodb-migrations).findAndModify or optimistic concurrency for critical migrations.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Migration script crash | Partial schema/data corruption | Atomic transactions (MongoDB 4.0+). |
| Network timeout | Hanging migrations | Set socketTimeoutMS in connection. |
| Invalid BSON data | Migration failure | Validate data before migration. |
| Permission denied | Blocked migrations | Use IAM roles with least privilege. |
| **MongoDB |
How can I help you explore Laravel packages today?