Commit 5a3ba68a by Daniel Lee

database: fixes after xorm update

parent 1c20126f
...@@ -255,7 +255,7 @@ func SetAlertState(cmd *m.SetAlertStateCommand) error { ...@@ -255,7 +255,7 @@ func SetAlertState(cmd *m.SetAlertStateCommand) error {
} }
alert.State = cmd.State alert.State = cmd.State
alert.StateChanges += 1 alert.StateChanges++
alert.NewStateDate = timeNow() alert.NewStateDate = timeNow()
alert.EvalData = cmd.EvalData alert.EvalData = cmd.EvalData
......
...@@ -46,6 +46,7 @@ func TestDashboardFolderDataAccess(t *testing.T) { ...@@ -46,6 +46,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
OrgId: 1, DashboardIds: []int64{folder.Id, dashInRoot.Id}, OrgId: 1, DashboardIds: []int64{folder.Id, dashInRoot.Id},
} }
err := SearchDashboards(query) err := SearchDashboards(query)
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(len(query.Result), ShouldEqual, 1) So(len(query.Result), ShouldEqual, 1)
So(query.Result[0].Id, ShouldEqual, dashInRoot.Id) So(query.Result[0].Id, ShouldEqual, dashInRoot.Id)
......
...@@ -2,6 +2,7 @@ package sqlstore ...@@ -2,6 +2,7 @@ package sqlstore
import ( import (
"testing" "testing"
"time"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
...@@ -241,6 +242,8 @@ func TestAccountDataAccess(t *testing.T) { ...@@ -241,6 +242,8 @@ func TestAccountDataAccess(t *testing.T) {
func testHelperUpdateDashboardAcl(dashboardId int64, items ...m.DashboardAcl) error { func testHelperUpdateDashboardAcl(dashboardId int64, items ...m.DashboardAcl) error {
cmd := m.UpdateDashboardAclCommand{DashboardId: dashboardId} cmd := m.UpdateDashboardAclCommand{DashboardId: dashboardId}
for _, item := range items { for _, item := range items {
item.Created = time.Now()
item.Updated = time.Now()
cmd.Items = append(cmd.Items, &item) cmd.Items = append(cmd.Items, &item)
} }
return UpdateDashboardAcl(&cmd) return UpdateDashboardAcl(&cmd)
......
...@@ -2,6 +2,7 @@ package sqlstore ...@@ -2,6 +2,7 @@ package sqlstore
import ( import (
"fmt" "fmt"
"time"
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
m "github.com/grafana/grafana/pkg/models" m "github.com/grafana/grafana/pkg/models"
...@@ -100,6 +101,7 @@ func UpdateOrgQuota(cmd *m.UpdateOrgQuotaCmd) error { ...@@ -100,6 +101,7 @@ func UpdateOrgQuota(cmd *m.UpdateOrgQuotaCmd) error {
quota := m.Quota{ quota := m.Quota{
Target: cmd.Target, Target: cmd.Target,
OrgId: cmd.OrgId, OrgId: cmd.OrgId,
Updated: time.Now(),
} }
has, err := sess.Get(&quota) has, err := sess.Get(&quota)
if err != nil { if err != nil {
...@@ -107,6 +109,7 @@ func UpdateOrgQuota(cmd *m.UpdateOrgQuotaCmd) error { ...@@ -107,6 +109,7 @@ func UpdateOrgQuota(cmd *m.UpdateOrgQuotaCmd) error {
} }
quota.Limit = cmd.Limit quota.Limit = cmd.Limit
if has == false { if has == false {
quota.Created = time.Now()
//No quota in the DB for this target, so create a new one. //No quota in the DB for this target, so create a new one.
if _, err := sess.Insert(&quota); err != nil { if _, err := sess.Insert(&quota); err != nil {
return err return err
...@@ -200,6 +203,7 @@ func UpdateUserQuota(cmd *m.UpdateUserQuotaCmd) error { ...@@ -200,6 +203,7 @@ func UpdateUserQuota(cmd *m.UpdateUserQuotaCmd) error {
quota := m.Quota{ quota := m.Quota{
Target: cmd.Target, Target: cmd.Target,
UserId: cmd.UserId, UserId: cmd.UserId,
Updated: time.Now(),
} }
has, err := sess.Get(&quota) has, err := sess.Get(&quota)
if err != nil { if err != nil {
...@@ -207,6 +211,7 @@ func UpdateUserQuota(cmd *m.UpdateUserQuotaCmd) error { ...@@ -207,6 +211,7 @@ func UpdateUserQuota(cmd *m.UpdateUserQuotaCmd) error {
} }
quota.Limit = cmd.Limit quota.Limit = cmd.Limit
if has == false { if has == false {
quota.Created = time.Now()
//No quota in the DB for this target, so create a new one. //No quota in the DB for this target, so create a new one.
if _, err := sess.Insert(&quota); err != nil { if _, err := sess.Insert(&quota); err != nil {
return err return err
......
...@@ -104,12 +104,12 @@ func TestQuotaCommandsAndQueries(t *testing.T) { ...@@ -104,12 +104,12 @@ func TestQuotaCommandsAndQueries(t *testing.T) {
}) })
}) })
Convey("Given saved user quota for org", func() { Convey("Given saved user quota for org", func() {
userQoutaCmd := m.UpdateUserQuotaCmd{ userQuotaCmd := m.UpdateUserQuotaCmd{
UserId: userId, UserId: userId,
Target: "org_user", Target: "org_user",
Limit: 10, Limit: 10,
} }
err := UpdateUserQuota(&userQoutaCmd) err := UpdateUserQuota(&userQuotaCmd)
So(err, ShouldBeNil) So(err, ShouldBeNil)
Convey("Should be able to get saved quota by user id and target", func() { Convey("Should be able to get saved quota by user id and target", func() {
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"testing" "testing"
"time"
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log" "github.com/grafana/grafana/pkg/log"
...@@ -225,8 +226,8 @@ var ( ...@@ -225,8 +226,8 @@ var (
func InitTestDB(t *testing.T) *xorm.Engine { func InitTestDB(t *testing.T) *xorm.Engine {
selectedDb := dbSqlite selectedDb := dbSqlite
//selectedDb := dbMySql // selectedDb := dbMySql
//selectedDb := dbPostgres // selectedDb := dbPostgres
var x *xorm.Engine var x *xorm.Engine
var err error var err error
...@@ -245,6 +246,9 @@ func InitTestDB(t *testing.T) *xorm.Engine { ...@@ -245,6 +246,9 @@ func InitTestDB(t *testing.T) *xorm.Engine {
x, err = xorm.NewEngine(sqlutil.TestDB_Sqlite3.DriverName, sqlutil.TestDB_Sqlite3.ConnStr) x, err = xorm.NewEngine(sqlutil.TestDB_Sqlite3.DriverName, sqlutil.TestDB_Sqlite3.ConnStr)
} }
x.DatabaseTZ = time.UTC
x.TZLocation = time.UTC
// x.ShowSQL() // x.ShowSQL()
if err != nil { if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment