Added expire option to dashboard snapshots, #1623
This commit is contained in:
@@ -21,8 +21,8 @@ func TestApiKeyDataAccess(t *testing.T) {
|
||||
Convey("Should be able to get key by name", func() {
|
||||
query := m.GetApiKeyByNameQuery{KeyName: "hello", OrgId: 1}
|
||||
err = GetApiKeyByName(&query)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
So(query.Result, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
|
||||
@@ -16,10 +16,17 @@ func init() {
|
||||
func CreateDashboardSnapshot(cmd *m.CreateDashboardSnapshotCommand) error {
|
||||
return inTransaction(func(sess *xorm.Session) error {
|
||||
|
||||
// never
|
||||
var expires = time.Now().Add(time.Hour * 24 * 365 * 50)
|
||||
if cmd.Expires > 0 {
|
||||
expires = time.Now().Add(time.Second * time.Duration(cmd.Expires))
|
||||
}
|
||||
|
||||
snapshot := &m.DashboardSnapshot{
|
||||
Key: cmd.Key,
|
||||
OrgId: cmd.OrgId,
|
||||
Dashboard: cmd.Dashboard,
|
||||
Expires: time.Unix(0, 0),
|
||||
Expires: expires,
|
||||
Created: time.Now(),
|
||||
Updated: time.Now(),
|
||||
}
|
||||
@@ -32,8 +39,8 @@ func CreateDashboardSnapshot(cmd *m.CreateDashboardSnapshotCommand) error {
|
||||
}
|
||||
|
||||
func GetDashboardSnapshot(query *m.GetDashboardSnapshotQuery) error {
|
||||
var snapshot m.DashboardSnapshot
|
||||
has, err := x.Where("key=?", query.Key).Get(&snapshot)
|
||||
snapshot := m.DashboardSnapshot{Key: query.Key}
|
||||
has, err := x.Get(&snapshot)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -21,4 +21,10 @@ func addDashboardSnapshotMigrations(mg *Migrator) {
|
||||
|
||||
mg.AddMigration("create dashboard_snapshot table v4", NewAddTableMigration(snapshotV4))
|
||||
addTableIndicesMigrations(mg, "v4", snapshotV4)
|
||||
|
||||
mg.AddMigration("add org_id to dashboard_snapshot", new(AddColumnMigration).
|
||||
Table("dashboard_snapshot").Column(&Column{Name: "org_id", Type: DB_BigInt, Nullable: true}))
|
||||
|
||||
mg.AddMigration("add index org_id to dashboard_snapshot",
|
||||
NewAddIndexMigration(snapshotV4, &Index{Cols: []string{"org_id"}}))
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
var (
|
||||
x *xorm.Engine
|
||||
dialect migrator.Dialect
|
||||
tables []interface{}
|
||||
|
||||
HasEngine bool
|
||||
|
||||
@@ -80,10 +79,6 @@ func SetEngine(engine *xorm.Engine, enableLog bool) (err error) {
|
||||
return fmt.Errorf("Sqlstore::Migration failed err: %v\n", err)
|
||||
}
|
||||
|
||||
if err := x.Sync2(tables...); err != nil {
|
||||
return fmt.Errorf("sync database struct error: %v\n", err)
|
||||
}
|
||||
|
||||
if enableLog {
|
||||
logPath := path.Join(setting.LogRootPath, "xorm.log")
|
||||
os.MkdirAll(path.Dir(logPath), os.ModePerm)
|
||||
@@ -94,11 +89,13 @@ func SetEngine(engine *xorm.Engine, enableLog bool) (err error) {
|
||||
}
|
||||
x.Logger = xorm.NewSimpleLogger(f)
|
||||
|
||||
x.ShowSQL = true
|
||||
x.ShowInfo = true
|
||||
x.ShowDebug = true
|
||||
x.ShowErr = true
|
||||
x.ShowWarn = true
|
||||
if setting.Env == setting.DEV {
|
||||
x.ShowSQL = false
|
||||
x.ShowInfo = false
|
||||
x.ShowDebug = false
|
||||
x.ShowErr = true
|
||||
x.ShowWarn = true
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -125,7 +122,7 @@ func getEngine() (*xorm.Engine, error) {
|
||||
DbCfg.User, DbCfg.Pwd, host, port, DbCfg.Name, DbCfg.SslMode)
|
||||
case "sqlite3":
|
||||
os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm)
|
||||
cnnstr = "file:" + DbCfg.Path + "?cache=shared&mode=rwc"
|
||||
cnnstr = "file:" + DbCfg.Path + "?cache=shared&mode=rwc&_loc=Local"
|
||||
default:
|
||||
return nil, fmt.Errorf("Unknown database type: %s", DbCfg.Type)
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
-timeout=10s
|
||||
@@ -11,7 +11,7 @@ type TestDB struct {
|
||||
ConnStr string
|
||||
}
|
||||
|
||||
var TestDB_Sqlite3 = TestDB{DriverName: "sqlite3", ConnStr: ":memory:"}
|
||||
var TestDB_Sqlite3 = TestDB{DriverName: "sqlite3", ConnStr: ":memory:?_loc=Local"}
|
||||
var TestDB_Mysql = TestDB{DriverName: "mysql", ConnStr: "grafana:password@tcp(localhost:3306)/grafana_tests?charset=utf8"}
|
||||
var TestDB_Postgres = TestDB{DriverName: "postgres", ConnStr: "user=grafanatest password=grafanatest host=localhost port=5432 dbname=grafanatest sslmode=disable"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user