feat: [#635] Optimize the process of generating migration and model (#2)#1049
feat: [#635] Optimize the process of generating migration and model (#2)#1049krishankumar01 merged 54 commits intomasterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1049 +/- ##
==========================================
+ Coverage 68.42% 68.56% +0.14%
==========================================
Files 264 264
Lines 15484 15566 +82
==========================================
+ Hits 10595 10673 +78
- Misses 4425 4430 +5
+ Partials 464 463 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi @kkumar-gcc Thanks for your great PR, and FYI, v1.16 is going to be released in about one/two weeks. It would be great if it can be merged before that. Or v1.17 is fine as well. |
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes the migration and model generation process by introducing a new structmeta package for struct introspection and a model mapper that automatically generates migration schema from Go struct models. The changes enable automatic migration generation from model definitions with GORM tags, streamlining the development workflow.
Key changes:
- Added
structmetapackage for runtime struct metadata extraction including fields, methods, and tags - Implemented automatic migration schema generation from Go models with GORM tag parsing
- Extended Schema to support model registration and retrieval
- Updated migration command to accept a
--modelflag for automatic schema generation
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| support/structmeta/type.go | Defines metadata structures for struct introspection (fields, methods, tags) |
| support/structmeta/structmeta_test.go | Test coverage for struct walking and tag parsing functionality |
| support/structmeta/structmeta.go | Core implementation for walking structs and extracting metadata |
| database/migration/model_mapper.go | Maps Go struct models to migration schema lines with GORM tag support |
| database/migration/model_mapper_test.go | Comprehensive tests for model-to-migration conversion |
| database/migration/stubs.go | Updated migration templates to use template variables and support dynamic schema fields |
| database/migration/migrator.go | Enhanced to generate migrations from models using templates and formatting |
| database/migration/migrator_test.go | Updated test to pass empty model name parameter |
| database/schema/schema.go | Added model storage, retrieval, and name extraction functionality |
| database/schema/schema_test.go | Tests for model extension and retrieval |
| database/console/migration/migrate_make_command.go | Added --model flag support for automatic migration generation |
| contracts/database/schema/schema.go | Added Model type and GetModel method to Schema interface |
| contracts/database/migration/migrator.go | Updated Create signature to include modelName parameter |
| mocks/database/schema/Schema.go | Generated mock for new GetModel method |
| mocks/database/migration/Migrator.go | Updated mock for Create with modelName parameter |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
hwbrzzl
left a comment
There was a problem hiding this comment.
Thanks, amazing PR. I successfully generated the migration. Left a few questions.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 21 out of 21 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
hwbrzzl
left a comment
There was a problem hiding this comment.
Thanks, almost there. Please check the Copilot comments as well, optimize them if necessary.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Fixed! For gorm.DeletedAt, the field is now correctly marked as .Nullable(). |
hwbrzzl
left a comment
There was a problem hiding this comment.
Awesome, we were finally here. 💯


📑 Description
Closes goravel/goravel#635
This PR adds a new flag
-m/--modelto themake:migrationcommand. It will try to resolve the provided model and generate a migration file based on that model. This feature mostly relies ongormtags to support custom behavior.Below is how you can use this feature:
Note
The model registration (discovery) can be optimized further. Currently, it registers model instances, but this can be improved. Looking for more suggestions on how to make this process cleaner and more efficient.
Call
make:migrationcommand to generate:go run . artisan make:migration -m AllFeaturesBelow is the generated migration file:
✅ Checks