- Can I use DataMigrationBundle to sync data between Laravel environments (e.g., staging to production) without SQL dumps?
- Yes, but with limitations. The bundle captures Doctrine entity changes (create/update/delete) via ORM events and exports them to version-controlled files (JSON/XML/YAML). Import them via Artisan commands to replicate data. However, it doesn’t handle schema changes or complex relationships (e.g., polymorphic associations), so you’ll need Laravel Migrations for DDL sync.
- How do I install DataMigrationBundle in Laravel? Does it support Laravel 10?
- Install via Composer: `composer require appventus/datamigration-bundle`. The bundle targets Symfony/Laravel but may not fully support Laravel 10 due to its archived status. Check the [usage docs](https://github.com/AppVentus/DataMigrationBundle/blob/master/Resources/documentation/usage.md) for compatibility notes. You may need to fork or patch it for newer Laravel versions.
- Will this bundle work with Eloquent models if I’m not using Doctrine ORM?
- No, DataMigrationBundle is tightly coupled to Doctrine ORM and won’t work with Eloquent-only projects. If you’re using Eloquent, consider alternatives like custom event listeners with JSON storage or packages like `spatie/laravel-model-states` for state-based migrations.
- How do I exclude sensitive fields (e.g., passwords, API tokens) from exported migration files?
- The bundle doesn’t natively filter sensitive fields, so you’ll need to manually configure excluded properties in your entity mappings or pre-process data before export. Add a `getExcludedProperties()` method to your entities or use Doctrine lifecycle callbacks to sanitize data before it’s recorded.
- Is DataMigrationBundle safe for production use? What about data corruption risks?
- Use with caution. The bundle lacks built-in validation for exported data (e.g., malformed JSON) and has no rollback mechanism. Test thoroughly in staging first, and always back up your database before importing. For high-stakes environments, consider writing custom validation or using a transactional wrapper around the import command.
- Can I migrate large datasets (e.g., 500K+ records) efficiently? Are there performance optimizations?
- No, the bundle isn’t optimized for large datasets. Export/import commands are blocking and add overhead via Doctrine event listeners, which can slow down write operations. For bulk migrations, chunk exports manually or explore alternatives like Laravel’s `Model::insert()` with batch processing or queue-based imports.
- How do I handle conflicts if I import data that already exists in the target database?
- The bundle overwrites target data by default with no built-in conflict resolution. To avoid duplicates, manually filter records before import or use Doctrine’s `merge()` method in a custom listener. For complex scenarios, consider implementing a merge strategy (e.g., upsert logic) in your entity mappings.
- What databases does DataMigrationBundle support? Will it work with PostgreSQL or SQL Server?
- It’s primarily tested with Doctrine DBAL (SQLite, MySQL, PostgreSQL). While PostgreSQL may work, SQL Server and NoSQL databases aren’t officially supported. Schema-agnostic design assumes source/target schemas are identical, so you’ll need to handle DDL differences separately via Laravel Migrations.
- Are there alternatives to DataMigrationBundle for Laravel that handle data migration better?
- Yes. For Eloquent projects, consider `spatie/laravel-model-states` (state-based migrations) or `orchestra/database` (advanced seeding). For Doctrine, custom event listeners + JSON storage offer more control. If you need cross-environment sync, evaluate message queues (Laravel Horizon) or API-based solutions for microservices.
- How do I test data integrity after importing migrations? Are there built-in validation tools?
- There’s no built-in validation, so you’ll need to write custom tests. Compare record counts, critical fields, or use Laravel’s `assertDatabaseHas()` in PHPUnit. For complex data, implement checksums or diff tools (e.g., `roave/security-advisories`) to verify integrity post-import.