- How do I install this package for Laravel?
- Run `composer require --dev kitloong/laravel-migrations-generator` in your project. Laravel auto-discovers the package, so no additional setup is needed unless you're using Lumen. For Lumen, manually register the service provider in `bootstrap/app.php` and enable facades.
- Which Laravel versions does this package support?
- The package supports Laravel 9+ and requires PHP 8.0+. It aligns with Laravel’s first-party database drivers (MySQL, PostgreSQL, SQL Server, SQLite, MariaDB). Always verify compatibility by checking your PHP version with `php -r "echo PHP_VERSION;"` before installation.
- Can I generate migrations for specific tables only?
- Yes, use the `--tables` flag to target specific tables, e.g., `php artisan migrate:generate --tables="users,posts"`. Alternatively, exclude tables with `--ignore="table1,table2"` to skip them during generation.
- Does this handle foreign keys and indexes automatically?
- Yes, the package generates Laravel migrations with columns, indexes, and foreign keys. However, circular dependencies may require manual table ordering or the `--squash` flag to combine migrations into a single file.
- How do I validate generated migrations before applying them?
- Test in a staging environment first. Use `php artisan migrate:fresh` to validate against a clean database, or compare output with manual migrations using `diff` or Laravel Debugbar. For complex schemas, manually review foreign keys and constraints.
- Will this work with SQL Server-specific features like computed columns?
- The package supports SQL Server but may struggle with non-standard features like computed columns or stored procedures. Test with `--dry-run` first, and manually adjust migrations for unsupported syntax. For edge cases, consider pre-processing your schema.
- Can I integrate this into my CI/CD pipeline?
- Yes, add it as a pre-merge check in GitHub Actions or similar tools. Example: `php artisan migrate:generate --dry-run --tables="users"`. Use `--dry-run` to preview changes without writing files, ensuring migrations align with your workflow.
- How do I handle conflicts if I merge generated migrations with manual changes?
- Generated migrations assume a ‘fresh’ schema, so conflicts may arise with manual changes. Use `--with-has-table` to check for existing tables, and manually resolve conflicts by comparing files. Consider adding a comment header (e.g., `// Auto-generated`) to track auto-generated vs. manual migrations.
- Does this package support custom migration templates?
- Yes, override default templates with the `--template-path` flag. For example, `php artisan migrate:generate --template-path=custom/templates` lets you define custom column or table structures while preserving Laravel’s syntax.
- What are the performance considerations for large databases?
- Performance degrades with >100 tables. Pre-filter tables with `--tables` or use `--squash` to reduce file count. For large schemas, test with a subset of tables first, and consider splitting migrations into batches for better CI/CD performance.