Skip to content

Commit db25516

Browse files
committed
switch DB bug fix
1 parent 17bae04 commit db25516

1 file changed

Lines changed: 36 additions & 36 deletions

File tree

server/internal/infrastructure/mongo/container.go

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,41 +25,41 @@ import (
2525
"go.mongodb.org/mongo-driver/mongo/options"
2626
)
2727

28-
func New(ctx context.Context, db *mongo.Database, account *accountrepo.Container, useTransaction bool) (*repo.Container, error) {
28+
func New(ctx context.Context, db *mongo.Database, accountContainer_With_ReearthAccountDbClient *accountrepo.Container, useTransaction bool) (*repo.Container, error) {
2929
lock, err := NewLock(db.Collection("locks"))
3030
if err != nil {
3131
return nil, err
3232
}
3333

34-
client := mongox.NewClientWithDatabase(db)
34+
reearthDbClient := mongox.NewClientWithDatabase(db)
3535
if useTransaction {
36-
client = client.WithTransaction()
36+
reearthDbClient = reearthDbClient.WithTransaction()
3737
}
3838

3939
c := &repo.Container{
40-
Asset: NewAsset(client),
41-
AuthRequest: authserver.NewMongo(client.WithCollection("authRequest")),
40+
Asset: NewAsset(reearthDbClient),
41+
AuthRequest: authserver.NewMongo(reearthDbClient.WithCollection("authRequest")),
4242
Config: NewConfig(db.Collection("config"), lock),
43-
DatasetSchema: NewDatasetSchema(client),
44-
Dataset: NewDataset(client),
45-
Layer: NewLayer(client),
46-
NLSLayer: NewNLSLayer(client),
47-
Style: NewStyle(client),
48-
Plugin: NewPlugin(client),
49-
Project: NewProject(client),
50-
PropertySchema: NewPropertySchema(client),
51-
Property: NewProperty(client),
52-
Scene: NewScene(client),
53-
Tag: NewTag(client),
54-
SceneLock: NewSceneLock(client),
55-
Permittable: NewPermittableWrapper(client), // TODO: Delete this once the permission check migration is complete.
56-
Policy: NewPolicy(client),
57-
Role: NewRoleWrapper(client), // TODO: Delete this once the permission check migration is complete.
58-
Storytelling: NewStorytelling(client),
43+
DatasetSchema: NewDatasetSchema(reearthDbClient),
44+
Dataset: NewDataset(reearthDbClient),
45+
Layer: NewLayer(reearthDbClient),
46+
NLSLayer: NewNLSLayer(reearthDbClient),
47+
Style: NewStyle(reearthDbClient),
48+
Plugin: NewPlugin(reearthDbClient),
49+
Project: NewProject(reearthDbClient),
50+
PropertySchema: NewPropertySchema(reearthDbClient),
51+
Property: NewProperty(reearthDbClient),
52+
Scene: NewScene(reearthDbClient),
53+
Tag: NewTag(reearthDbClient),
54+
SceneLock: NewSceneLock(reearthDbClient),
55+
Permittable: NewPermittableWrapper(reearthDbClient), // TODO: Delete this once the permission check migration is complete.
56+
Policy: NewPolicy(reearthDbClient),
57+
Role: NewRoleWrapper(reearthDbClient), // TODO: Delete this once the permission check migration is complete.
58+
Storytelling: NewStorytelling(reearthDbClient),
5959
Lock: lock,
60-
Transaction: client.Transaction(),
61-
Workspace: NewWorkspaceWrapper(client),
62-
User: NewUserWrapper(client),
60+
Transaction: reearthDbClient.Transaction(),
61+
Workspace: accountContainer_With_ReearthAccountDbClient.Workspace,
62+
User: accountContainer_With_ReearthAccountDbClient.User,
6363
}
6464

6565
// init
@@ -68,7 +68,7 @@ func New(ctx context.Context, db *mongo.Database, account *accountrepo.Container
6868
}
6969

7070
// migration
71-
if err := migration.Do(ctx, client, c.Config); err != nil {
71+
if err := migration.Do(ctx, reearthDbClient, c.Config); err != nil {
7272
return nil, err
7373
}
7474

@@ -134,8 +134,7 @@ func Init(r *repo.Container) error {
134134
func() error { return r.Role.(*RoleWrapper).Init(ctx) }, // TODO: Delete this once the permission check migration is complete.
135135
func() error { return r.Scene.(*Scene).Init(ctx) },
136136
func() error { return r.Tag.(*Tag).Init(ctx) },
137-
func() error { return r.User.(*UserWrapper).Init() },
138-
func() error { return r.Workspace.(*WorkspaceWrapper).Init() },
137+
// User and Workspace are already initialized in accountRepoContainer
139138
)
140139
}
141140

@@ -228,26 +227,27 @@ func createIndexesOnly(ctx context.Context, c *mongox.ClientCollection, keys, un
228227
}
229228

230229
// NewAccountRepoContainer creates account repositories using wrappers that prevent index dropping
231-
func NewAccountRepoContainer(ctx context.Context, client *mongo.Client, database string, txAvailable, accountRepoCompat bool, accountUsers []accountrepo.User) (*accountrepo.Container, error) {
232-
mongoxClient := mongox.NewClient(database, client)
230+
func NewAccountRepoContainer(ctx context.Context, client *mongo.Client, accountDBName string, txAvailable, accountRepoCompat bool, accountUsers []accountrepo.User) (*accountrepo.Container, error) {
231+
// log.Debug("Account DB Name:", accountDBName)
232+
reearthAccountDbClient := mongox.NewClient(accountDBName, client)
233233
if txAvailable {
234-
mongoxClient = mongoxClient.WithTransaction()
234+
reearthAccountDbClient = reearthAccountDbClient.WithTransaction()
235235
}
236236

237237
var ws accountrepo.Workspace
238238
if accountRepoCompat {
239-
ws = NewWorkspaceWrapper(mongoxClient)
239+
ws = NewWorkspaceWrapper(reearthAccountDbClient)
240240
} else {
241-
ws = NewWorkspaceWrapper(mongoxClient)
241+
ws = NewWorkspaceWrapper(reearthAccountDbClient)
242242
}
243243

244244
container := &accountrepo.Container{
245245
Workspace: ws,
246-
User: NewUserWrapper(mongoxClient),
247-
Transaction: mongoxClient.Transaction(),
246+
User: NewUserWrapper(reearthAccountDbClient),
247+
Transaction: reearthAccountDbClient.Transaction(),
248248
Users: accountUsers,
249-
Role: NewRoleWrapper(mongoxClient),
250-
Permittable: NewPermittableWrapper(mongoxClient),
249+
Role: NewRoleWrapper(reearthAccountDbClient),
250+
Permittable: NewPermittableWrapper(reearthAccountDbClient),
251251
}
252252

253253
if err := initAccountWrappers(container); err != nil {

0 commit comments

Comments
 (0)