dotted-ai / laravel-db-introspector
There is no license information available for the latest version (dev-main) of this package.
Generate migrations from existing database schema
dev-main
2025-07-08 19:00 UTC
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-07-08 19:00:50 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/migrations
to place generated files.
Examples
-
Generate migrations for all tables, skip existing:
php artisan db:generate-migrations
-
Generate only
users
andposts
, 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