feat(dev): allow passing struct name to dev:make-migration mage command (#931)

This commit is contained in:
kolaente
2025-06-12 13:06:07 +02:00
committed by GitHub
parent 3e7c0099c8
commit 8d5c665781
2 changed files with 14 additions and 11 deletions

View File

@@ -26,8 +26,8 @@ The project consists of:
- **Clean**: `mage build:clean` - Cleans build artifacts
- **Format**: `mage fmt` - Format Go code before committing
Development helpers under the `dev` namespace:
- **Migration**: `mage dev:make-migration` - Creates new database migration
-Development helpers under the `dev` namespace:
- **Migration**: `mage dev:make-migration <StructName>` - Creates new database migration. If you omit `<StructName>`, the command will prompt for it.
- **Event**: `mage dev:make-event` - Create an event type
- **Listener**: `mage dev:make-listener` - Create an event listener
- **Notification**: `mage dev:make-notification` - Create a notification skeleton
@@ -114,7 +114,7 @@ Modern Vue 3 composition API application with TypeScript:
**Backend Changes:**
1. Create/modify models in `pkg/models/` with proper CRUD and Rights interfaces as required
2. Add database migration if needed: `mage dev:make-migration`
2. Add database migration if needed: `mage dev:make-migration <StructName>`
3. Create/update services in `pkg/services/` for complex business logic
4. Add API routes in `pkg/routes/api/v1/` following existing patterns
5. Update Swagger annotations
@@ -127,7 +127,7 @@ Modern Vue 3 composition API application with TypeScript:
5. Update Pinia stores if global state changes are needed
### Database Changes
1. Run `mage dev:make-migration` and enter the struct name
1. Run `mage dev:make-migration <StructName>`
2. Edit the generated migration file in `pkg/migration/`
3. Update corresponding model in `pkg/models/`
4. Update TypeScript interfaces in frontend `src/modelTypes/`

View File

@@ -998,13 +998,16 @@ func (Release) Packages() error {
type Dev mg.Namespace
// Creates a new bare db migration skeleton in pkg/migration with the current date
func (Dev) MakeMigration() error {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter the name of the struct: ")
str, _ := reader.ReadString('\n')
str = strings.Trim(str, "\n")
// MakeMigration creates a new bare db migration skeleton in pkg/migration.
// If you pass the struct name as an argument, the prompt will be skipped.
func (Dev) MakeMigration(name string) error {
str := strings.TrimSpace(name)
if str == "" {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter the name of the struct: ")
s, _ := reader.ReadString('\n')
str = strings.TrimSpace(s)
}
date := time.Now().Format("20060102150405")