Skip to content

Commit

Permalink
chore(server): enable to set visualizer db name by .env (#1345)
Browse files Browse the repository at this point in the history
  • Loading branch information
soneda-yuya authored Jan 10, 2025
1 parent 887173f commit 52f66e4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion server/.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# General
PORT=8080
REEARTH_DB=mongodb://localhost
REEARTH_DB=mongodb://localhost # for reearth database url
REEARTH_DB_ACCOUNT=reearth_account # for reearth account database name
REEARTH_DB_VIS=reearth # for reearth visualizer database name
REEARTH_HOST=https://localhost:8080
REEARTH_HOST_WEB=https://localhost:3000
REEARTH_ASSETBASEURL=https://localhost:8080/assets
Expand Down
1 change: 1 addition & 0 deletions server/internal/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Config struct {
DB string `default:"mongodb://localhost"`
DB_Account string `pp:",omitempty"`
DB_Users []appx.NamedURI `pp:",omitempty"`
DB_Vis string `pp:",omitempty"`
GraphQL GraphQLConfig `pp:",omitempty"`
Published PublishedConfig `pp:",omitempty"`
GCPProject string `envconfig:"GOOGLE_CLOUD_PROJECT" pp:",omitempty"`
Expand Down
15 changes: 11 additions & 4 deletions server/internal/app/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import (
"go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo"
)

const databaseName = "reearth"
const defaultVisDatabase = "reearth"
const defaultAccountDatabase = "reearth_account"

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 +43,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 = defaultAccountDatabase
accountRepoCompat = true
}

Expand All @@ -66,7 +67,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 visualizer database
visDatabase := conf.DB_Vis
if visDatabase == "" {
visDatabase = defaultVisDatabase
}

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

0 comments on commit 52f66e4

Please sign in to comment.