kitloong/laravel-migrations-generator
Generate Laravel migration files from an existing database schema, including columns, indexes, and foreign keys. Works with MariaDB/MySQL, PostgreSQL, SQL Server, and SQLite. Generate all tables or target/ignore specific tables via Artisan.
Pros:
Cons:
timestamps, softDeletes), which may require post-generation adjustments.--squash is used).JSONB, SQL Server’s NVARCHAR) may not map cleanly to Laravel’s Blueprint syntax without manual overrides.--dev dependency, isolating it from production environments.migrate:generate) without modifying core Laravel behavior.down() methods).vendor/ size; negligible for most projects but worth noting for constrained environments.phpunit/database/tests/) adapt to auto-generated files?SQLite in-memory databases) that could cause failures?withFacades() and provider registration).php artisan ide-helper:generate).orchestra/testbench for testing auto-generated migrations.laravel-schema for runtime schema inspection.--tables="users,posts") and manually review.--squash for monolithic schemas to reduce file count.# In CI pipeline
if [ "$BRANCH" == "main" ]; then
php artisan migrate:generate --squash --path="database/migrations" --skip-log
git add database/migrations/
git commit -m "chore: regenerate migrations"
fi
--with-has-table to avoid errors on existing tables.Blueprint changes).composer.json constraints).UUID, ARRAY, or JSONB types.NVARCHAR or DATETIME2 may require custom type mappings.:memory: cautiously).config/database.php for correct connection settings.php artisan migrate:generate with flags tailored to the project (e.g., --tables, --ignore, --connection).--squash to avoid hundreds of files.php artisan migrate:fresh --seed in a test environment.phpunit.xml to include new migration tests.up()/down() logic).post-deploy script or Git hook).git diff to identify changes between manual and auto-generated migrations.php artisan migrate:rollback works for auto-generated files (test down() methods).--squash or manual ordering).Blueprint types in generated files (e.g., ->string() → ->text()).--connection flag matches config/database.php.--log-with-batch=0 to debug migration execution order.MIGRATIONS.md file listing auto-generated files and their sources.--template-path).--tables batches or using --squash.composer require --dev kitloong/laravel-migrations-generator).| Failure Scenario | Mitigation | Recovery |
|---|---|---|
| Corrupted migration generation | Run with --skip-log to avoid partial migrations in the migrations table. |
Manually roll back and regenerate. |
| Foreign key circular dependencies | Use --squash or manually order tables. |
Drop and recreate constraints in down() methods. |
| Database connection issues | Validate --connection flag and config/database.php. |
Retry with correct connection or use a backup database. |
| Type mapping failures | Override Blueprint types in generated files. |
Manually edit |
How can I help you explore Laravel packages today?