Establish a relationship between actions and the agents targeted by them when actions are inserted into postgres

This commit is contained in:
Zack Mullaly 2018-10-31 16:20:32 -04:00
Родитель f2e60c0403
Коммит a611f5587c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 1486642516ED3535
1 изменённых файлов: 13 добавлений и 0 удалений

Просмотреть файл

@ -202,6 +202,19 @@ func (db *DB) InsertAction(a mig.Action) (err error) {
if err != nil {
return fmt.Errorf("Failed to store action: '%v'", err)
}
// The following query establishes a relation between the new action and all
// agents targeted by the action.
_, err = db.c.Exec(fmt.Sprintf(`
insert into agent_action_relation (agent_id, action_id)
select $1, A.id
from agents A
where (%s);
`, a.Target), a.ID)
if err != nil {
return fmt.Errorf("Failed to establish relation between action and targeted agents: '%s'", err.Error())
}
return
}