You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by kl...@apache.org on 2023/07/04 08:27:14 UTC
[incubator-devlake] branch main updated: test: added debug code to scope_generic_helper to troubleshoot why the test domain is acting up and failing to delete some records (#5581)
This is an automated email from the ASF dual-hosted git repository.
klesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new b82a4c0e8 test: added debug code to scope_generic_helper to troubleshoot why the test domain is acting up and failing to delete some records (#5581)
b82a4c0e8 is described below
commit b82a4c0e823dbbaed06d8c68c2e99fdc1a5b5efc
Author: Keon Amini <ke...@merico.dev>
AuthorDate: Tue Jul 4 03:27:09 2023 -0500
test: added debug code to scope_generic_helper to troubleshoot why the test domain is acting up and failing to delete some records (#5581)
---
.../pluginhelper/api/scope_generic_helper.go | 24 ++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/backend/helpers/pluginhelper/api/scope_generic_helper.go b/backend/helpers/pluginhelper/api/scope_generic_helper.go
index 985732f54..99c2725f1 100644
--- a/backend/helpers/pluginhelper/api/scope_generic_helper.go
+++ b/backend/helpers/pluginhelper/api/scope_generic_helper.go
@@ -623,8 +623,7 @@ func (gs *GenericScopeApiHelper[Conn, Scope, ScopeConfig]) deleteScopeData(scope
}
func (gs *GenericScopeApiHelper[Conn, Scope, ScopeConfig]) transactionalDelete(tables []string, rawDataParams string) errors.Error {
- tx := gs.db.Begin()
- for _, table := range tables {
+ generateWhereClause := func(table string) (string, []any) {
var where string
var params []interface{}
if strings.HasPrefix(table, "_raw_") {
@@ -647,6 +646,12 @@ func (gs *GenericScopeApiHelper[Conn, Scope, ScopeConfig]) transactionalDelete(t
rawDataTablePrefix := fmt.Sprintf("_raw_%s%%", gs.plugin)
params = []interface{}{rawDataTablePrefix, rawDataParams}
}
+ return where, params
+ }
+ tx := gs.db.Begin()
+ for _, table := range tables {
+ where, params := generateWhereClause(table)
+ gs.log.Info("deleting data from table %s with WHERE \"%s\" and params: \"%v\"", table, where, params)
sql := fmt.Sprintf("DELETE FROM %s WHERE %s", table, where)
err := tx.Exec(sql, params...)
if err != nil {
@@ -661,6 +666,21 @@ func (gs *GenericScopeApiHelper[Conn, Scope, ScopeConfig]) transactionalDelete(t
if err != nil {
return errors.Default.Wrap(err, "error committing delete transaction for plugin tables")
}
+ // validate everything was deleted
+ var failedTables []string
+ for _, table := range tables {
+ where, params := generateWhereClause(table)
+ count, err := gs.db.Count(dal.From(table), dal.Where(where, params...))
+ if err != nil {
+ return err
+ }
+ if count > 0 {
+ failedTables = append(failedTables, table)
+ }
+ }
+ if len(failedTables) > 0 {
+ return errors.Default.New(fmt.Sprintf("Failed to delete all expected rows from the following table(s): %v", failedTables))
+ }
return nil
}