From 1d70aa0637d99c9fb7b6bcb53bd1036ce7be44bb Mon Sep 17 00:00:00 2001 From: Hayden Spitzley <105455169+hspitzley-czi@users.noreply.github.com> Date: Fri, 20 Oct 2023 15:09:56 -0400 Subject: [PATCH] chore: rename dbutil package to store (#2616) --- api/pkg/api/app.go | 10 +++++----- api/pkg/api/app_test.go | 4 ++-- api/pkg/cmd/cmd_test.go | 6 +++--- api/pkg/cmd/config.go | 6 +++--- api/pkg/cmd/stack.go | 4 ++-- api/pkg/{dbutil => store}/db.go | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) rename api/pkg/{dbutil => store}/db.go (98%) diff --git a/api/pkg/api/app.go b/api/pkg/api/app.go index ebcddda108..46689ff165 100644 --- a/api/pkg/api/app.go +++ b/api/pkg/api/app.go @@ -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" @@ -21,7 +21,7 @@ import ( type APIApplication struct { FiberApp *fiber.App - DB *dbutil.DB + DB *store.DB Cfg *setup.Configuration } @@ -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{ @@ -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 { diff --git a/api/pkg/api/app_test.go b/api/pkg/api/app_test.go index cb00a47b5a..a73cfb79f3 100644 --- a/api/pkg/api/app_test.go +++ b/api/pkg/api/app_test.go @@ -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" @@ -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 } diff --git a/api/pkg/cmd/cmd_test.go b/api/pkg/cmd/cmd_test.go index 2cab382842..02185a2b29 100644 --- a/api/pkg/cmd/cmd_test.go +++ b/api/pkg/cmd/cmd_test.go @@ -5,9 +5,9 @@ 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" ) @@ -15,7 +15,7 @@ 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 @@ -23,5 +23,5 @@ func MakeTestDB(t *testing.T) *dbutil.DB { 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) } diff --git a/api/pkg/cmd/config.go b/api/pkg/cmd/config.go index bb976be7da..55d3f6942a 100644 --- a/api/pkg/cmd/config.go +++ b/api/pkg/cmd/config.go @@ -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" @@ -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, } diff --git a/api/pkg/cmd/stack.go b/api/pkg/cmd/stack.go index 8250dc6649..82db56fd11 100644 --- a/api/pkg/cmd/stack.go +++ b/api/pkg/cmd/stack.go @@ -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" ) @@ -17,7 +17,7 @@ type StackManager interface { type Stack struct{} -func MakeStack(db *dbutil.DB) StackManager { +func MakeStack(db *store.DB) StackManager { return &Stack{} } diff --git a/api/pkg/dbutil/db.go b/api/pkg/store/db.go similarity index 98% rename from api/pkg/dbutil/db.go rename to api/pkg/store/db.go index 37af50490a..7f5a83e15f 100644 --- a/api/pkg/dbutil/db.go +++ b/api/pkg/store/db.go @@ -1,4 +1,4 @@ -package dbutil +package store import ( "context"