fix(lagoon): run deferred:purge and the migrate commands on the app's published database (quick-261106-kt2)
The nightly framework entry deferred:purge failed under serve's worker and schedule:run with "backpack: duplicate provider for *sql.DB": withDB always opened and published a second pool. It now reuses the published *gorm.DB and leaves that pool open; the CLI path (nothing published) is unchanged.
This commit is contained in:
@@ -483,7 +483,16 @@ func purgeBucket(ctx context.Context, app *backpack.App) (*blob.Bucket, func(),
|
||||
return b, func() { _ = b.Close() }, nil
|
||||
}
|
||||
|
||||
// withDB runs fn on the app's published database when there is one: an
|
||||
// in-process run (the scheduler in serve or schedule:run, through
|
||||
// bonfire.Catalog.Call) borrows that pool and leaves it open. Otherwise it
|
||||
// opens and publishes a pool for the CLI run and closes it when fn returns.
|
||||
func withDB(ctx context.Context, app *backpack.App, fn func(*gorm.DB) error) error {
|
||||
if app != nil {
|
||||
if gdb, ok := app.Lookup[*gorm.DB](); ok && gdb != nil {
|
||||
return fn(gdb)
|
||||
}
|
||||
}
|
||||
sqlDB, gdb, err := OpenFromApp(ctx, app)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user