shared providers: allow to immediately re-add soft-deleted event rules

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino 2022-11-01 17:39:53 +01:00
parent 9d7e30807d
commit 3b2002d9ef
No known key found for this signature in database
GPG key ID: 935D2952DEC4EECF
2 changed files with 10 additions and 0 deletions

View file

@ -3133,6 +3133,12 @@ func sqlCommonAddEventRule(rule *EventRule, dbHandle *sql.DB) error {
defer cancel() defer cancel()
return sqlCommonExecuteTx(ctx, dbHandle, func(tx *sql.Tx) error { return sqlCommonExecuteTx(ctx, dbHandle, func(tx *sql.Tx) error {
if config.IsShared == 1 {
_, err := tx.ExecContext(ctx, getRemoveSoftDeletedRuleQuery(), rule.Name)
if err != nil {
return err
}
}
q := getAddEventRuleQuery() q := getAddEventRuleQuery()
_, err := tx.ExecContext(ctx, q, rule.Name, rule.Description, util.GetTimeAsMsSinceEpoch(time.Now()), _, err := tx.ExecContext(ctx, q, rule.Name, rule.Description, util.GetTimeAsMsSinceEpoch(time.Now()),
util.GetTimeAsMsSinceEpoch(time.Now()), rule.Trigger, string(conditions)) util.GetTimeAsMsSinceEpoch(time.Now()), rule.Trigger, string(conditions))

View file

@ -895,6 +895,10 @@ func getDeleteEventRuleQuery(softDelete bool) string {
return fmt.Sprintf(`DELETE FROM %s WHERE name = %s`, sqlTableEventsRules, sqlPlaceholders[0]) return fmt.Sprintf(`DELETE FROM %s WHERE name = %s`, sqlTableEventsRules, sqlPlaceholders[0])
} }
func getRemoveSoftDeletedRuleQuery() string {
return fmt.Sprintf(`DELETE FROM %s WHERE name = %s AND deleted_at > 0`, sqlTableEventsRules, sqlPlaceholders[0])
}
func getClearRuleActionMappingQuery() string { func getClearRuleActionMappingQuery() string {
return fmt.Sprintf(`DELETE FROM %s WHERE rule_id = (SELECT id FROM %s WHERE name = %s)`, sqlTableRulesActionsMapping, return fmt.Sprintf(`DELETE FROM %s WHERE rule_id = (SELECT id FROM %s WHERE name = %s)`, sqlTableRulesActionsMapping,
sqlTableEventsRules, sqlPlaceholders[0]) sqlTableEventsRules, sqlPlaceholders[0])