mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
adding created column
This commit is contained in:
parent
624dac16fa
commit
3898ea02e6
@ -24,6 +24,7 @@ func GetAnnotations(c *m.ReqContext) Response {
|
|||||||
Limit: c.QueryInt64("limit"),
|
Limit: c.QueryInt64("limit"),
|
||||||
Tags: c.QueryStrings("tags"),
|
Tags: c.QueryStrings("tags"),
|
||||||
Type: c.Query("type"),
|
Type: c.Query("type"),
|
||||||
|
Sort: c.Query("sort"),
|
||||||
}
|
}
|
||||||
|
|
||||||
repo := annotations.GetRepository()
|
repo := annotations.GetRepository()
|
||||||
|
@ -20,6 +20,7 @@ type ItemQuery struct {
|
|||||||
RegionId int64 `json:"regionId"`
|
RegionId int64 `json:"regionId"`
|
||||||
Tags []string `json:"tags"`
|
Tags []string `json:"tags"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
Sort string `json:"sort"`
|
||||||
|
|
||||||
Limit int64 `json:"limit"`
|
Limit int64 `json:"limit"`
|
||||||
}
|
}
|
||||||
@ -63,6 +64,7 @@ type Item struct {
|
|||||||
PrevState string `json:"prevState"`
|
PrevState string `json:"prevState"`
|
||||||
NewState string `json:"newState"`
|
NewState string `json:"newState"`
|
||||||
Epoch int64 `json:"epoch"`
|
Epoch int64 `json:"epoch"`
|
||||||
|
Created int64 `json:"created"`
|
||||||
Tags []string `json:"tags"`
|
Tags []string `json:"tags"`
|
||||||
Data *simplejson.Json `json:"data"`
|
Data *simplejson.Json `json:"data"`
|
||||||
|
|
||||||
@ -80,6 +82,7 @@ type ItemDTO struct {
|
|||||||
UserId int64 `json:"userId"`
|
UserId int64 `json:"userId"`
|
||||||
NewState string `json:"newState"`
|
NewState string `json:"newState"`
|
||||||
PrevState string `json:"prevState"`
|
PrevState string `json:"prevState"`
|
||||||
|
Created int64 `json:"created"`
|
||||||
Time int64 `json:"time"`
|
Time int64 `json:"time"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
RegionId int64 `json:"regionId"`
|
RegionId int64 `json:"regionId"`
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
"github.com/grafana/grafana/pkg/services/annotations"
|
"github.com/grafana/grafana/pkg/services/annotations"
|
||||||
@ -17,6 +18,7 @@ func (r *SqlAnnotationRepo) Save(item *annotations.Item) error {
|
|||||||
return inTransaction(func(sess *DBSession) error {
|
return inTransaction(func(sess *DBSession) error {
|
||||||
tags := models.ParseTagPairs(item.Tags)
|
tags := models.ParseTagPairs(item.Tags)
|
||||||
item.Tags = models.JoinTagPairs(tags)
|
item.Tags = models.JoinTagPairs(tags)
|
||||||
|
item.Created = time.Now().UnixNano() / int64(time.Millisecond)
|
||||||
if _, err := sess.Table("annotation").Insert(item); err != nil {
|
if _, err := sess.Table("annotation").Insert(item); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -127,6 +129,7 @@ func (r *SqlAnnotationRepo) Find(query *annotations.ItemQuery) ([]*annotations.I
|
|||||||
annotation.text,
|
annotation.text,
|
||||||
annotation.tags,
|
annotation.tags,
|
||||||
annotation.data,
|
annotation.data,
|
||||||
|
annotation.created,
|
||||||
usr.email,
|
usr.email,
|
||||||
usr.login,
|
usr.login,
|
||||||
alert.name as alert_name
|
alert.name as alert_name
|
||||||
@ -205,7 +208,17 @@ func (r *SqlAnnotationRepo) Find(query *annotations.ItemQuery) ([]*annotations.I
|
|||||||
query.Limit = 10
|
query.Limit = 10
|
||||||
}
|
}
|
||||||
|
|
||||||
sql.WriteString(fmt.Sprintf(" ORDER BY epoch DESC LIMIT %v", query.Limit))
|
var sort string = "epoch DESC"
|
||||||
|
switch query.Sort {
|
||||||
|
case "time.asc":
|
||||||
|
sort = "epoch ASC"
|
||||||
|
case "created":
|
||||||
|
sort = "annotation.created DESC"
|
||||||
|
case "created.asc":
|
||||||
|
sort = "annotation.created ASC"
|
||||||
|
}
|
||||||
|
|
||||||
|
sql.WriteString(fmt.Sprintf(" ORDER BY %s LIMIT %v", sort, query.Limit))
|
||||||
|
|
||||||
items := make([]*annotations.ItemDTO, 0)
|
items := make([]*annotations.ItemDTO, 0)
|
||||||
|
|
||||||
|
@ -90,4 +90,14 @@ func addAnnotationMig(mg *Migrator) {
|
|||||||
Sqlite(updateTextFieldSql).
|
Sqlite(updateTextFieldSql).
|
||||||
Postgres(updateTextFieldSql).
|
Postgres(updateTextFieldSql).
|
||||||
Mysql(updateTextFieldSql))
|
Mysql(updateTextFieldSql))
|
||||||
|
|
||||||
|
//
|
||||||
|
// Add a 'created' column
|
||||||
|
//
|
||||||
|
mg.AddMigration("Add created time to annotation table", NewAddColumnMigration(table, &Column{
|
||||||
|
Name: "created", Type: DB_BigInt, Nullable: true, Default: "0",
|
||||||
|
}))
|
||||||
|
mg.AddMigration("Add index for created in annotation table", NewAddIndexMigration(table, &Index{
|
||||||
|
Cols: []string{"org_id", "created"}, Type: IndexType,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user