database: fixes after xorm update

This commit is contained in:
Daniel Lee
2018-03-16 00:09:29 +01:00
parent 1c20126f87
commit 5a3ba68a9c
6 changed files with 22 additions and 9 deletions
+9 -4
View File
@@ -2,6 +2,7 @@ package sqlstore
import (
"fmt"
"time"
"github.com/grafana/grafana/pkg/bus"
m "github.com/grafana/grafana/pkg/models"
@@ -98,8 +99,9 @@ func UpdateOrgQuota(cmd *m.UpdateOrgQuotaCmd) error {
return inTransaction(func(sess *DBSession) error {
//Check if quota is already defined in the DB
quota := m.Quota{
Target: cmd.Target,
OrgId: cmd.OrgId,
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
@@ -198,8 +201,9 @@ func UpdateUserQuota(cmd *m.UpdateUserQuotaCmd) error {
return inTransaction(func(sess *DBSession) error {
//Check if quota is already defined in the DB
quota := m.Quota{
Target: cmd.Target,
UserId: cmd.UserId,
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