mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
chore: remove sqlstore & mockstore dependencies from (most) packages (#57087)
* chore: add alias for InitTestDB and Session Adds an alias for the sqlstore InitTestDB and Session, and updates tests using these to reduce dependencies on the sqlstore.Store. * next pass of removing sqlstore imports * last little bit * remove mockstore where possible
This commit is contained in:
@@ -4,9 +4,8 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||
)
|
||||
|
||||
type store interface {
|
||||
@@ -23,7 +22,7 @@ type xormStore struct {
|
||||
}
|
||||
|
||||
func (ss *xormStore) UpdateTempUserStatus(ctx context.Context, cmd *models.UpdateTempUserStatusCommand) error {
|
||||
return ss.db.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
return ss.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
var rawSQL = "UPDATE temp_user SET status=? WHERE code=?"
|
||||
_, err := sess.Exec(rawSQL, string(cmd.Status), cmd.Code)
|
||||
return err
|
||||
@@ -31,7 +30,7 @@ func (ss *xormStore) UpdateTempUserStatus(ctx context.Context, cmd *models.Updat
|
||||
}
|
||||
|
||||
func (ss *xormStore) CreateTempUser(ctx context.Context, cmd *models.CreateTempUserCommand) error {
|
||||
return ss.db.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
return ss.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
// create user
|
||||
user := &models.TempUser{
|
||||
Email: cmd.Email,
|
||||
@@ -58,7 +57,7 @@ func (ss *xormStore) CreateTempUser(ctx context.Context, cmd *models.CreateTempU
|
||||
}
|
||||
|
||||
func (ss *xormStore) UpdateTempUserWithEmailSent(ctx context.Context, cmd *models.UpdateTempUserWithEmailSentCommand) error {
|
||||
return ss.db.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
return ss.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
user := &models.TempUser{
|
||||
EmailSent: true,
|
||||
EmailSentOn: time.Now(),
|
||||
@@ -71,7 +70,7 @@ func (ss *xormStore) UpdateTempUserWithEmailSent(ctx context.Context, cmd *model
|
||||
}
|
||||
|
||||
func (ss *xormStore) GetTempUsersQuery(ctx context.Context, query *models.GetTempUsersQuery) error {
|
||||
return ss.db.WithDbSession(ctx, func(dbSess *sqlstore.DBSession) error {
|
||||
return ss.db.WithDbSession(ctx, func(dbSess *db.Session) error {
|
||||
rawSQL := `SELECT
|
||||
tu.id as id,
|
||||
tu.org_id as org_id,
|
||||
@@ -111,7 +110,7 @@ func (ss *xormStore) GetTempUsersQuery(ctx context.Context, query *models.GetTem
|
||||
}
|
||||
|
||||
func (ss *xormStore) GetTempUserByCode(ctx context.Context, query *models.GetTempUserByCodeQuery) error {
|
||||
return ss.db.WithDbSession(ctx, func(dbSess *sqlstore.DBSession) error {
|
||||
return ss.db.WithDbSession(ctx, func(dbSess *db.Session) error {
|
||||
var rawSQL = `SELECT
|
||||
tu.id as id,
|
||||
tu.org_id as org_id,
|
||||
@@ -146,7 +145,7 @@ func (ss *xormStore) GetTempUserByCode(ctx context.Context, query *models.GetTem
|
||||
}
|
||||
|
||||
func (ss *xormStore) ExpireOldUserInvites(ctx context.Context, cmd *models.ExpireTempUsersCommand) error {
|
||||
return ss.db.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
return ss.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
var rawSQL = "UPDATE temp_user SET status = ?, updated = ? WHERE created <= ? AND status in (?, ?)"
|
||||
if result, err := sess.Exec(rawSQL, string(models.TmpUserExpired), time.Now().Unix(), cmd.OlderThan.Unix(), string(models.TmpUserSignUpStarted), string(models.TmpUserInvitePending)); err != nil {
|
||||
return err
|
||||
|
||||
@@ -5,9 +5,10 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
func TestIntegrationTempUserCommandsAndQueries(t *testing.T) {
|
||||
@@ -23,7 +24,7 @@ func TestIntegrationTempUserCommandsAndQueries(t *testing.T) {
|
||||
Status: models.TmpUserInvitePending,
|
||||
}
|
||||
setup := func(t *testing.T) {
|
||||
db := sqlstore.InitTestDB(t)
|
||||
db := db.InitTestDB(t)
|
||||
store = &xormStore{db: db}
|
||||
err := store.CreateTempUser(context.Background(), &cmd)
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -3,8 +3,8 @@ package tempuserimpl
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||
tempuser "github.com/grafana/grafana/pkg/services/temp_user"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user