@@ -37,7 +37,23 @@ func Upgrade(ctx context.Context, databaseID, plan string, wait bool) error {
3737 return errors .Newf (ctx , "no addons found for database application %s" , db .App .ID )
3838 }
3939
40- _ , err = c .AddonUpgrade (ctx , db .App .ID , addons [0 ].ID , scalingo.AddonUpgradeParams {
40+ var dbAddon * scalingo.Addon
41+ if db .Database .ResourceID != "" {
42+ for _ , addon := range addons {
43+ if addon .ResourceID == db .Database .ResourceID {
44+ dbAddon = addon
45+ break
46+ }
47+ }
48+ }
49+ if dbAddon == nil && len (addons ) == 1 {
50+ dbAddon = addons [0 ]
51+ }
52+ if dbAddon == nil {
53+ return errors .Newf (ctx , "no addon matching database %s (%s) found for application %s" , db .Name , db .ID , db .App .ID )
54+ }
55+
56+ _ , err = c .AddonUpgrade (ctx , db .App .ID , dbAddon .ID , scalingo.AddonUpgradeParams {
4157 PlanID : planID ,
4258 })
4359 if err != nil {
@@ -54,14 +70,13 @@ func Upgrade(ctx context.Context, databaseID, plan string, wait bool) error {
5470 spin := spinner .New (spinner .CharSets [11 ], 100 * time .Millisecond )
5571 spin .Suffix = " Waiting for the plan change to complete\n "
5672 spin .Start ()
57- defer spin .Stop ()
5873
5974 err = waitForDatabasePlanChange (ctx , c , db .ID )
75+ spin .Stop ()
6076 if err != nil {
6177 return errors .Wrap (ctx , err , "wait for database plan change" )
6278 }
6379
64- spin .Stop ()
6580 io .Status ("Your database plan change is complete." )
6681 }
6782
@@ -87,7 +102,9 @@ func waitForDatabasePlanChange(ctx context.Context, client *scalingo.Client, dat
87102}
88103
89104func waitForDatabaseStatus (ctx context.Context , client * scalingo.Client , databaseID string , check func (scalingo.DatabaseStatus ) bool ) error {
90- for range time .Tick (10 * time .Second ) {
105+ ticker := time .NewTicker (10 * time .Second )
106+ defer ticker .Stop ()
107+ for range ticker .C {
91108 db , err := client .Preview ().DatabaseShow (ctx , databaseID )
92109 if errors .Is (err , scalingo .ErrDatabaseNotFound ) {
93110 continue
0 commit comments