Skip to content

Commit 43df33e

Browse files
committed
refactor(cli): Refactor CLI to support lazy app resolution and enhance migration command handling
- Updated `buildServeCommand`, `buildMigrateCommand`, and related functions to resolve the app context lazily during command execution. - Introduced `appProvider` in CLI configuration for deferred app creation. - Enhanced migration command registration and execution, ensuring commands can access the app context dynamically. - Added tests for lazy app resolution and global flag injection. - Updated documentation to reflect changes in running apps and CLI options. - Improved error handling for app availability in command contexts.
1 parent eafbb06 commit 43df33e

File tree

13 files changed

+906
-195
lines changed

13 files changed

+906
-195
lines changed

app.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ type App interface {
4141
// Extensions
4242
Extensions() []Extension
4343
GetExtension(name string) (Extension, error)
44+
45+
// Configuration queries
46+
MigrationsDisabled() bool
4447
}
4548

4649
// AppConfig configures the application.
@@ -93,6 +96,9 @@ type AppConfig struct {
9396
EnvPrefix string // Prefix for environment variables (default: app name uppercase, e.g., "MYAPP_")
9497
EnvSeparator string // Separator for nested keys in env vars (default: "_")
9598
EnvOverridesFile bool // Whether env vars override file config values (default: true)
99+
100+
// Database / Migration
101+
DisableMigrations bool // When true, skip auto-migrations on serve (default: false). Also settable via .forge.yaml database.disable_migrations.
96102
}
97103

98104
// DefaultAppConfig returns a default application configuration.
@@ -319,6 +325,12 @@ func WithEnvOverridesFile(override bool) AppOption {
319325
}
320326
}
321327

328+
// WithDisableMigrations disables auto-migrations on serve.
329+
// This can also be set via .forge.yaml under database.disable_migrations.
330+
func WithDisableMigrations() AppOption {
331+
return func(c *AppConfig) { c.DisableMigrations = true }
332+
}
333+
322334
// NewApp creates a new Forge application.
323335
func NewApp(config AppConfig) App {
324336
return newApp(config)

app_impl.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,11 @@ func (a *app) Environment() string {
476476
return a.config.Environment
477477
}
478478

479+
// MigrationsDisabled returns true if auto-migrations are disabled via config or .forge.yaml.
480+
func (a *app) MigrationsDisabled() bool {
481+
return a.config.DisableMigrations
482+
}
483+
479484
// StartTime returns the application start time.
480485
func (a *app) StartTime() time.Time {
481486
a.mu.RLock()
@@ -1367,6 +1372,9 @@ type forgeYAMLConfig struct {
13671372
Build struct {
13681373
Output string `yaml:"output"`
13691374
} `yaml:"build"`
1375+
Database struct {
1376+
DisableMigrations bool `yaml:"disable_migrations"`
1377+
} `yaml:"database"`
13701378
}
13711379

13721380
// loadForgeYAMLConfig searches for and loads .forge.yaml to configure runtime settings.
@@ -1455,5 +1463,13 @@ func loadForgeYAMLConfig(config AppConfig, logger Logger) AppConfig {
14551463
}
14561464
}
14571465

1466+
// Set DisableMigrations from .forge.yaml if not already set programmatically
1467+
if !config.DisableMigrations && forgeConfig.Database.DisableMigrations {
1468+
config.DisableMigrations = true
1469+
if logger != nil {
1470+
logger.Info("migrations disabled via .forge.yaml", F("path", forgeConfigPath))
1471+
}
1472+
}
1473+
14581474
return config
14591475
}

0 commit comments

Comments
 (0)