- How do I generate Laravel migrations for an existing MySQL database without losing data?
- Run `php artisan php-my-migration:generate` to scan your database and create migration files in `database/migrations/`. The package compares existing columns and data types, ensuring your schema matches the generated migrations while preserving data integrity. Always back up your database first.
- Does php-my-migration support Laravel 9 or 10, or is it only for Laravel 8?
- The package is designed for Laravel 8+ and should work with Laravel 9/10 due to stable migration system APIs. However, test with your specific Laravel version, as newer features (e.g., SpatialIndex) may require manual adjustments in generated migrations.
- Can I generate migrations for individual tables instead of the entire database?
- No, the package currently generates migrations for all tables in the database at once. For granular control, manually filter or split tables post-generation, or use `--dry-run` to preview changes before running the full command.
- What should I do if the generated migrations include unsupported MySQL features like triggers or custom collations?
- The package focuses on standard DDL (tables, columns, indexes, foreign keys). For unsupported features, manually edit the generated migration files or exclude those tables using `--exclude-tables` (if available). Validate changes in a staging environment before applying to production.
- How do I handle data type mismatches, like INT vs. BIGINT, between the existing schema and Laravel defaults?
- Use the `--dry-run` flag to preview changes and identify mismatches. The package syncs data types but may not always match Laravel’s defaults. Review and adjust the generated migrations manually, then test with `php artisan migrate --pretend` before applying.
- Is it safe to re-run php-my-migration on a schema that already has Laravel migrations?
- The package is idempotent for unchanged tables but will overwrite existing migration files if they conflict. Use `--skip-existing` (if supported) or manually merge changes. Always back up migrations and test in a staging environment before re-running.
- Can I integrate php-my-migration into my CI/CD pipeline for schema validation?
- Yes, add a pre-deployment step to run `php artisan php-my-migration:generate --dry-run` and compare output with your expected schema. Use Laravel’s `Schema::hasTable()` and `Schema::hasColumn()` for runtime checks in tests or deployment scripts.
- What’s the best way to validate generated migrations before applying them to production?
- Test migrations in a staging environment with `php artisan migrate --pretend` to simulate changes. Use Laravel’s `Schema::dump()` to compare the generated schema with your expected structure, and manually review edge cases like custom column options or constraints.
- Does php-my-migration handle foreign key constraints accurately, or do I need to fix them manually?
- The package attempts to preserve foreign key constraints in generated migrations, but complex relationships (e.g., multi-column keys or custom options) may require manual review. Test migrations thoroughly and use `--dry-run` to catch discrepancies early.
- Are there alternatives to php-my-migration for converting MySQL schemas to Laravel migrations?
- Alternatives include custom scripts using `DB::select()` to inspect schemas or third-party tools like Laravel Schema Builder extensions. However, php-my-migration is tailored for Laravel, offering seamless integration with Artisan and migration files while minimizing manual effort.