Skip to content

Conversation

@danteay
Copy link
Collaborator

@danteay danteay commented Jan 13, 2026

Summary

Enhanced the new:domain command with three major improvements:

  • Refactored mockery integration to reuse action layer instead of shell commands
  • Added CLI flags for non-interactive mode (CI/CD friendly)
  • Implemented dynamic database loading from .local-migrate-config.yml with PascalCase provider naming

Key Changes

1. Mockery Integration Refactor

  • Replaced shell command execution with direct mockery action calls in internal/actions/newdomain/mockery.go
  • Added context support for proper cancellation handling (Ctrl+C)
  • Concurrent mock generation with progress reporting
  • Better error handling and reporting

2. CLI Flags for Non-Interactive Mode

Added five new flags to skip interactive prompts:

  • --domain-path, -p: Path to the domain folder
  • --db-type: Database type (postgres or dynamo)
  • --table-name: Database table name
  • --db-prefix: ID prefix for Postgres (3 characters)
  • --db-name: Database name for Postgres

Updated form logic to:

  • Skip prompts when flag values are provided
  • Validate flag values with same rules as interactive inputs
  • Support mixed mode (some flags, some prompts)

3. Dynamic Database Configuration

Created new utility: internal/pkg/migrateconfig/

  • Reads .local-migrate-config.yml from project root
  • Parses migrations.databases configuration
  • Filters out test databases (group: 'test')
  • Converts snake_case to PascalCase for provider functions
    • Example: user_preferencesProvideUserPreferences
    • Example: games_coreProvideGamesCore

Updated postgres form to dynamically load databases instead of static list

4. Template Fixes

  • Fixed //go:embed directive to include .mockery.pkg.yml.tmpl files
  • Fixed Postgres provider template to:
    • Add missing context parameter to ProvideGeneral() call
    • Use providers.MustAs[gorm.Driver] for type assertion
    • Add missing gorm import

5. Enhanced Documentation

Updated command help with:

  • Comprehensive usage examples (interactive, non-interactive, mixed mode)
  • Detailed flag descriptions
  • Database configuration workflow explanation
  • PascalCase conversion examples

Test Results

✅ Postgres domain creation with flags
✅ DynamoDB domain creation with flags
✅ Dynamic database loading from config
✅ Test database filtering
✅ PascalCase conversion (user_preferences → ProvideUserPreferences)
✅ Mock generation with concurrent execution

Breaking Changes

None. All changes are backwards compatible with existing workflows.

Usage Examples

Interactive Mode (existing behavior)

draft new:domain

Non-Interactive Mode (new)

# Postgres
draft new:domain \
  --domain-path users \
  --db-type postgres \
  --table-name public.users \
  --db-prefix usr \
  --db-name general

# DynamoDB
draft new:domain \
  --domain-path products \
  --db-type dynamo \
  --table-name ProductsTable

Mixed Mode (new)

draft new:domain --domain-path orders --db-type postgres
# Prompts only for table-name, db-prefix, and db-name

Technical Details

Files Modified: 16 files

  • Command layer: CLI flags and documentation
  • Form layer: Dynamic database loading and flag support
  • Action layer: Mockery action integration
  • Template layer: Embed fixes and provider template corrections
  • New utility: Database configuration parser

Lines Changed: +470, -170

🤖 Generated with Claude Code

danteay and others added 3 commits January 13, 2026 16:45
Updated both CLAUDE.md and README.md to document the new features:

- CLI flags for non-interactive mode (--domain-path, --db-type, etc.)
- Dynamic database loading from .local-migrate-config.yml
- PascalCase conversion for provider function names
- Mockery action integration with context support
- Usage examples for interactive, non-interactive, and mixed modes
- Database configuration workflow

Changes include:
- Added comprehensive flag documentation
- Explained database configuration from .local-migrate-config.yml
- Documented PascalCase conversion (user_preferences -> ProvideUserPreferences)
- Updated mockery integration section
- Added migrateconfig utility to project structure
- Enhanced usage examples with all three modes

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Comment on lines +87 to 103
if input.DBName != "" {
validDBName := false
for _, dbName := range databases {
if dbName == input.DBName {
validDBName = true
break
}
}

if !validDBName {
availableDBs := make([]string, 0, len(databases))
for _, dbName := range databases {
availableDBs = append(availableDBs, dbName)
}
return fmt.Errorf("invalid db-name '%s': must be one of %v", input.DBName, availableDBs)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if input.DBName != "" {
validDBName := false
for _, dbName := range databases {
if dbName == input.DBName {
validDBName = true
break
}
}
if !validDBName {
availableDBs := make([]string, 0, len(databases))
for _, dbName := range databases {
availableDBs = append(availableDBs, dbName)
}
return fmt.Errorf("invalid db-name '%s': must be one of %v", input.DBName, availableDBs)
}
}
if input.DBName != "" {
validDBName := false
availableDBs := make([]string, 0, len(databases))
for _, dbName := range databases {
availableDBs = append(availableDBs, dbName)
if dbName == input.DBName {
validDBName = true
break
}
}
if !validDBName {
return fmt.Errorf("invalid db-name '%s': must be one of %v", input.DBName, availableDBs)
}
}

podriamos evitar iterar dos veces databases

@danteay danteay merged commit ec2e797 into main Jan 16, 2026
2 checks passed
@danteay danteay deleted the fix/new-domain branch January 16, 2026 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants