Fixed a bug of leaking resource cofig scope ids.
package db
import (
+ "database/sql"
"errors"
"fmt"
"time"
@@ -124,8 +125,19 @@ func findOrCreateResourceConfigScope(
}
var scopeID int
-
- rows, err := psql.Select("id").
+ var rows *sql.Rows
+ var err error
+ if uniqueResourceID == nil {
+ rows, err = psql.Select("id").
+ From("resource_config_scopes").
+ Where(sq.Eq{
+ "resource_config_id": resourceConfig.ID(),
+ }).
+ Where(sq.Expr("resource_id IS NULL")).
+ RunWith(tx).
+ Query()
+ } else {
+ rows, err = psql.Select("id").
From("resource_config_scopes").
Where(sq.Eq{
"resource_id": resourceID,
@@ -133,6 +145,7 @@ func findOrCreateResourceConfigScope(
}).
RunWith(tx).
Query()
+ }
if err != nil {
return nil, err
}
