Commit 5a3ba68a by Daniel Lee

database: fixes after xorm update

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