From 830c86efe779c41315cd67b36ab6e53145e85ed8 Mon Sep 17 00:00:00 2001 From: Denis Makogon Date: Thu, 21 Sep 2017 02:04:27 +0300 Subject: [PATCH] Make app delete more stable We still need to delete app and check how may rows affected in apps table. But we don't really care about other tables and rows affected there: routes, calls, logs We need to delete app out of loop to check for invalid numbers of rows affected: - zero rows means nothing happend Despite apps table, zero rows affected if valid case for routes, calls and logs --- api/datastore/sql/sql.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/api/datastore/sql/sql.go b/api/datastore/sql/sql.go index 560f4345a..90416ea4e 100644 --- a/api/datastore/sql/sql.go +++ b/api/datastore/sql/sql.go @@ -222,13 +222,13 @@ func (ds *sqlStore) UpdateApp(ctx context.Context, newapp *models.App) (*models. func (ds *sqlStore) RemoveApp(ctx context.Context, appName string) error { return ds.Tx(func(tx *sqlx.Tx) error { - res, err := ds.db.ExecContext(ctx, ds.db.Rebind( - `DELETE FROM apps WHERE name = ?`), appName) + res, err := tx.ExecContext(ctx, tx.Rebind(`DELETE FROM apps WHERE name=?`), appName) + n, err := res.RowsAffected() if err != nil { return err } - _, err = res.RowsAffected() - if err == sql.ErrNoRows { + + if n == 0 { return models.ErrAppsNotFound } @@ -239,12 +239,11 @@ func (ds *sqlStore) RemoveApp(ctx context.Context, appName string) error { } for _, stmt := range deletes { - _, err = ds.db.ExecContext(ctx, ds.db.Rebind(stmt), appName) + _, err := tx.ExecContext(ctx, tx.Rebind(stmt), appName) if err != nil { return err } } - return nil }) }