fix: use strings.HasPrefix and delegate export to real cleanup method
- Replace manual string prefix check with strings.HasPrefix (idiomatic Go) - Refactor CleanupCancelledDeploy export to call the real cleanupCancelledDeploy method instead of re-implementing the logic, so tests catch regressions - Add nil-db guard in Deployment.Save and App.Save to prevent panics when models are used without a database connection (e.g. in test exports) - Fix wsl_v5 lint issue (missing blank line before assignment)
This commit is contained in:
@@ -62,6 +62,10 @@ func NewApp(db *database.Database) *App {
|
||||
|
||||
// Save inserts or updates the app in the database.
|
||||
func (a *App) Save(ctx context.Context) error {
|
||||
if a.db == nil {
|
||||
return fmt.Errorf("no database connection")
|
||||
}
|
||||
|
||||
if a.exists(ctx) {
|
||||
return a.update(ctx)
|
||||
}
|
||||
|
||||
@@ -57,6 +57,10 @@ func NewDeployment(db *database.Database) *Deployment {
|
||||
|
||||
// Save inserts or updates the deployment in the database.
|
||||
func (d *Deployment) Save(ctx context.Context) error {
|
||||
if d.db == nil {
|
||||
return fmt.Errorf("no database connection")
|
||||
}
|
||||
|
||||
if d.ID == 0 {
|
||||
return d.insert(ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user