Skip to content

Commit

Permalink
chore(server): enable to set visualizer db name by .env
Browse files Browse the repository at this point in the history
  • Loading branch information
soneda-yuya committed Jan 10, 2025
1 parent 887173f commit 55dfe84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions server/internal/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Config struct {
Dev bool `pp:",omitempty"`
DB string `default:"mongodb://localhost"`
DB_Account string `pp:",omitempty"`
DB_Visualizer string `pp:",omitempty"`
DB_Users []appx.NamedURI `pp:",omitempty"`
GraphQL GraphQLConfig `pp:",omitempty"`
Published PublishedConfig `pp:",omitempty"`
Expand Down
14 changes: 10 additions & 4 deletions server/internal/app/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo"
)

const databaseName = "reearth"
const defaultDatabase = "reearth"

func initReposAndGateways(ctx context.Context, conf *config.Config, debug bool) (*repo.Container, *gateway.Container, *accountrepo.Container, *accountgateway.Container) {
gateways := &gateway.Container{}
Expand All @@ -42,11 +42,11 @@ func initReposAndGateways(ctx context.Context, conf *config.Config, debug bool)
log.Fatalf("mongo error: %+v\n", err)
}

// repos
// for account database
accountDatabase := conf.DB_Account
accountRepoCompat := false
if accountDatabase == "" {
accountDatabase = databaseName
accountDatabase = defaultDatabase
accountRepoCompat = true
}

Expand All @@ -66,7 +66,13 @@ func initReposAndGateways(ctx context.Context, conf *config.Config, debug bool)
log.Fatalf("Failed to init mongo: %+v\n", err)
}

repos, err := mongorepo.NewWithExtensions(ctx, client.Database(databaseName), accountRepos, txAvailable, conf.Ext_Plugin)
// for reearth database
visualizerDatabase := conf.DB_Visualizer
if visualizerDatabase == "" {
visualizerDatabase = defaultDatabase
}

repos, err := mongorepo.NewWithExtensions(ctx, client.Database(visualizerDatabase), accountRepos, txAvailable, conf.Ext_Plugin)
if err != nil {
log.Fatalf("Failed to init mongo: %+v\n", err)
}
Expand Down

0 comments on commit 55dfe84

Please sign in to comment.