2017-02-23 06:12:16 +01:00
|
|
|
package db
|
2016-04-16 21:42:57 +02:00
|
|
|
|
2017-02-23 06:12:16 +01:00
|
|
|
import "time"
|
2016-04-16 21:42:57 +02:00
|
|
|
|
2018-03-27 22:12:47 +02:00
|
|
|
// Event represents information generated by ansible or api action captured to the database during execution
|
2016-04-16 21:42:57 +02:00
|
|
|
type Event struct {
|
|
|
|
ProjectID *int `db:"project_id" json:"project_id"`
|
|
|
|
ObjectID *int `db:"object_id" json:"object_id"`
|
|
|
|
ObjectType *string `db:"object_type" json:"object_type"`
|
|
|
|
Description *string `db:"description" json:"description"`
|
|
|
|
Created time.Time `db:"created" json:"created"`
|
|
|
|
|
|
|
|
ObjectName string `db:"-" json:"object_name"`
|
|
|
|
ProjectName *string `db:"project_name" json:"project_name"`
|
|
|
|
}
|
2016-04-17 02:20:23 +02:00
|
|
|
|
2018-03-27 22:12:47 +02:00
|
|
|
// Insert writes the event to the database
|
2016-04-17 02:20:23 +02:00
|
|
|
func (evt Event) Insert() error {
|
2020-11-28 22:49:44 +01:00
|
|
|
_, err := Sql.Exec(
|
|
|
|
"insert into event(project_id, object_id, object_type, description, created) values (?, ?, ?, ?, ?)",
|
|
|
|
evt.ProjectID,
|
|
|
|
evt.ObjectID,
|
|
|
|
evt.ObjectType,
|
|
|
|
evt.Description,
|
|
|
|
time.Now().Format("2006-01-02 15:04:05"))
|
2016-04-17 02:20:23 +02:00
|
|
|
|
|
|
|
return err
|
|
|
|
}
|