Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(server): enable to set visualizer db name by .env #1345

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading