Skip to content

Commit

Permalink
chore: rename dbutil package to store (#2616)
Browse files Browse the repository at this point in the history
  • Loading branch information
hspitzley-czi authored Oct 20, 2023
1 parent a1affe8 commit 1d70aa0
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions api/pkg/api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"time"

"github.com/chanzuckerberg/happy/api/pkg/cmd"
"github.com/chanzuckerberg/happy/api/pkg/dbutil"
"github.com/chanzuckerberg/happy/api/pkg/request"
"github.com/chanzuckerberg/happy/api/pkg/setup"
"github.com/chanzuckerberg/happy/api/pkg/store"
"github.com/getsentry/sentry-go"
"github.com/gofiber/contrib/fibersentry"
"github.com/gofiber/fiber/v2"
Expand All @@ -21,7 +21,7 @@ import (

type APIApplication struct {
FiberApp *fiber.App
DB *dbutil.DB
DB *store.DB
Cfg *setup.Configuration
}

Expand All @@ -37,11 +37,11 @@ func MakeAPIApplication(cfg *setup.Configuration) *APIApplication {
}

func MakeApp(ctx context.Context, cfg *setup.Configuration) *APIApplication {
db := dbutil.MakeDB(cfg.Database)
db := store.MakeDB(cfg.Database)
return MakeAppWithDB(ctx, cfg, db)
}

func MakeAppWithDB(ctx context.Context, cfg *setup.Configuration, db *dbutil.DB) *APIApplication {
func MakeAppWithDB(ctx context.Context, cfg *setup.Configuration, db *store.DB) *APIApplication {
apiApp := MakeAPIApplication(cfg).WithDatabase(db)
apiApp.FiberApp.Use(requestid.New())
apiApp.FiberApp.Use(cors.New(cors.Config{
Expand Down Expand Up @@ -109,7 +109,7 @@ func MakeAppWithDB(ctx context.Context, cfg *setup.Configuration, db *dbutil.DB)
return apiApp
}

func (a *APIApplication) WithDatabase(db *dbutil.DB) *APIApplication {
func (a *APIApplication) WithDatabase(db *store.DB) *APIApplication {
a.DB = db
err := a.DB.AutoMigrate()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions api/pkg/api/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"testing"

"github.com/blang/semver"
"github.com/chanzuckerberg/happy/api/pkg/dbutil"
"github.com/chanzuckerberg/happy/api/pkg/ent/enttest"
"github.com/chanzuckerberg/happy/api/pkg/request"
"github.com/chanzuckerberg/happy/api/pkg/setup"
"github.com/chanzuckerberg/happy/api/pkg/store"
"github.com/gofiber/fiber/v2"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
Expand All @@ -31,7 +31,7 @@ func MakeTestApp(t *testing.T) *APIApplication {
client := enttest.Open(t, "sqlite3", fmt.Sprintf("file:memdb%s?mode=memory&cache=shared&_fk=1", uuid.NewString()))
mu.Unlock()

testDB := dbutil.MakeDB(cfg.Database).WithClient(client)
testDB := store.MakeDB(cfg.Database).WithClient(client)
app := MakeAppWithDB(context.Background(), cfg, testDB)
return app
}
Expand Down
6 changes: 3 additions & 3 deletions api/pkg/cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ import (
"sync"
"testing"

"github.com/chanzuckerberg/happy/api/pkg/dbutil"
"github.com/chanzuckerberg/happy/api/pkg/ent/enttest"
"github.com/chanzuckerberg/happy/api/pkg/setup"
"github.com/chanzuckerberg/happy/api/pkg/store"
"github.com/google/uuid"
)

var (
mu sync.Mutex
)

func MakeTestDB(t *testing.T) *dbutil.DB {
func MakeTestDB(t *testing.T) *store.DB {
config := setup.GetConfiguration()

// Even with a UUID in the data source name this is not thread safe so we need to use a mutex to prevent concurrent access
mu.Lock()
client := enttest.Open(t, "sqlite3", fmt.Sprintf("file:memdb%s?mode=memory&cache=shared&_fk=1", uuid.NewString()))
mu.Unlock()

return dbutil.MakeDB(config.Database).WithClient(client)
return store.MakeDB(config.Database).WithClient(client)
}
6 changes: 3 additions & 3 deletions api/pkg/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package cmd
import (
"context"

"github.com/chanzuckerberg/happy/api/pkg/dbutil"
"github.com/chanzuckerberg/happy/api/pkg/ent"
"github.com/chanzuckerberg/happy/api/pkg/ent/appconfig"
"github.com/chanzuckerberg/happy/api/pkg/store"
"github.com/chanzuckerberg/happy/shared/model"
"github.com/pkg/errors"
"github.com/samber/lo"
Expand All @@ -25,10 +25,10 @@ type Config interface {
}

type dbConfig struct {
DB *dbutil.DB
DB *store.DB
}

func MakeConfig(db *dbutil.DB) Config {
func MakeConfig(db *store.DB) Config {
return &dbConfig{
DB: db,
}
Expand Down
4 changes: 2 additions & 2 deletions api/pkg/cmd/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package cmd
import (
"context"

"github.com/chanzuckerberg/happy/api/pkg/dbutil"
"github.com/chanzuckerberg/happy/api/pkg/request"
"github.com/chanzuckerberg/happy/api/pkg/store"
"github.com/chanzuckerberg/happy/shared/model"
"github.com/pkg/errors"
)
Expand All @@ -17,7 +17,7 @@ type StackManager interface {

type Stack struct{}

func MakeStack(db *dbutil.DB) StackManager {
func MakeStack(db *store.DB) StackManager {
return &Stack{}
}

Expand Down
2 changes: 1 addition & 1 deletion api/pkg/dbutil/db.go → api/pkg/store/db.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dbutil
package store

import (
"context"
Expand Down

0 comments on commit 1d70aa0

Please sign in to comment.