dotted-ai / laravel-db-introspector
Generate migrations from existing database schema
Installs: 1 020
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/dotted-ai/laravel-db-introspector
Requires
- php: ^7.4|^8.0
- doctrine/dbal: ^3.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
This package is auto-updated.
Last update: 2025-12-08 19:54:15 UTC
README
A Laravel package to inspect an existing database schema and generate corresponding migration files automatically.
🚀 Installation
-
Require via Composer:
composer require dotted-ai/laravel-db-introspector
-
Publish the stub template (optional):
php artisan vendor:publish \ --provider="Vendor\DbIntrospector\DatabaseInspectorServiceProvider" \ --tag=stubs
🎯 Usage
Run the artisan command to generate migrations:
php artisan db:generate-migrations \
[--tables=users,posts] \
[--rewrite] \
[--output-dir=from_schema]
--tables=(optional): Comma-separated list of tables. If omitted, all tables are processed.--rewrite(optional): Overwrite existing migration files instead of skipping.--output-dir=(optional): Specify a subdirectory underdatabase/migrationsto place generated files.
Examples
-
Generate migrations for all tables, skip existing:
php artisan db:generate-migrations
-
Generate only
usersandposts, overwrite any existing:php artisan db:generate-migrations --tables=users,posts --rewrite
-
Output migrations to
database/migrations/from_schema:php artisan db:generate-migrations --output-dir=from_schema
⚙️ Configuration
You can customize the stub template located at database/stubs/db-introspector/migration.stub after publishing.
The stub uses placeholders:
{{class}}— migration class name{{table}}— table name{{fields}}— column definitions
🛠️ How It Works
- Introspection: Uses Doctrine DBAL to list tables and columns.
- Build: Maps Doctrine column types to Laravel schema methods.
- Generate: Writes migration files with timestamps to avoid naming conflicts.
📄 License
MIT © Your Company