Skip to content
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: 2 additions & 2 deletions server/internal/infrastructure/mongo/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func New(ctx context.Context, db *mongo.Database, account *accountrepo.Container
Storytelling: NewStorytelling(client),
Lock: lock,
Transaction: client.Transaction(),
Workspace: account.Workspace,
Workspace: NewWorkspaceWrapper(client),
User: account.User,
}

Expand Down Expand Up @@ -136,7 +136,7 @@ func Init(r *repo.Container) error {
func() error { return r.Scene.(*Scene).Init(ctx) },
func() error { return r.Tag.(*Tag).Init(ctx) },
func() error { return r.User.(*accountmongo.User).Init() },
func() error { return r.Workspace.(*accountmongo.Workspace).Init() },
func() error { return r.Workspace.(*WorkspaceWrapper).Init() },
)
}

Expand Down
35 changes: 35 additions & 0 deletions server/internal/infrastructure/mongo/workspace_wrapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package mongo

import (
"context"

"github.com/reearth/reearthx/account/accountinfrastructure/accountmongo"
"github.com/reearth/reearthx/account/accountusecase/accountrepo"
"github.com/reearth/reearthx/mongox"
)

// WorkspaceWrapper wraps accountmongo.Workspace to prevent index dropping
type WorkspaceWrapper struct {
*accountmongo.Workspace
client *mongox.Collection
}

// NewWorkspaceWrapper creates a workspace wrapper that doesn't drop indexes
func NewWorkspaceWrapper(client *mongox.Client) accountrepo.Workspace {
// Create the original workspace
original := accountmongo.NewWorkspace(client)

return &WorkspaceWrapper{
Workspace: original.(*accountmongo.Workspace),
client: client.WithCollection("workspace"),
}
}

// Init override to prevent index dropping - just create indexes without dropping existing ones
func (w *WorkspaceWrapper) Init() error {
ctx := context.Background()

// Only create the "id" unique index that the original workspace expects
// without calling the original Init() which would drop existing indexes
return createIndexesOnly(ctx, w.client, nil, []string{"id"})
}
Loading