mongodb seeding port#248
Open
jasonmorais wants to merge 4 commits into
Open
Conversation
Contributor
Reviewer's GuideAdds a seedable in-memory MongoDB replica server wired to mongoose and OCOM data models, wires a new seeding workflow into the mock MongoDB app, introduces initial community/user/member/role/property/service seed data, and performs minor dependency/test updates and formatting tweaks. Sequence diagram for mock MongoDB startup and seeding workflowsequenceDiagram
actor Developer
participant App as server_mongodb_memory_mock
participant Seedwork as startMockMongoDB
participant ReplSet as MongoMemoryReplSet
participant Mongoose as mongoose
participant Seeder as seedDatabase
Developer->>App: startMockMongoDB(config)
App->>Seedwork: startMockMongoDB(config)
Seedwork->>ReplSet: MongoMemoryReplSet.create({...})
ReplSet-->>Seedwork: replicaSet
Seedwork->>ReplSet: getUri(dbName)
ReplSet-->>Seedwork: uri
Seedwork->>Mongoose: connect(uri)
Mongoose-->>Seedwork: connection
loop [until collectionsToSeed exist]
Seedwork->>Mongoose: connection.db.listCollections()
Mongoose-->>Seedwork: collections
end
Seedwork->>Seeder: seedDatabase(connection)
Seeder-->>Seedwork: Promise<void>
Seedwork-->>App: resolved
App-->>Developer: mock MongoDB ready
Entity relationship diagram for seeded MongoDB mock dataerDiagram
EndUser {
string _id
}
Community {
string _id
string createdBy
}
EndUserRole {
string _id
string community
}
Member {
string _id
string community
string role
}
Property {
string _id
string community
string owner
}
Service {
string _id
string community
}
EndUser ||--o{ Community : createdBy
Community ||--o{ EndUserRole : has_roles
Community ||--o{ Member : has_members
Community ||--o{ Property : has_properties
Community ||--o{ Service : has_services
EndUser ||--o{ Member : has_accounts
EndUserRole ||--o{ Member : assigned_to
Member ||--o{ Property : owns_properties
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
…so added mongodb version to catalog
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The new
startMockMongoDBhelper no longer exposes a disposer or hooks into process shutdown signals, so there’s currently no clean way to stop the in-memory replica set; consider returning thereplicaSet(or a stop function) and wiring it into SIGINT/SIGTERM handling as before. - The
while (true)loop that waits forcollectionsToSeedhas no timeout or backoff and could hang the process indefinitely if collections never appear; adding a maximum wait duration and clearer error reporting would make failures easier to diagnose. - Several code paths in the seedwork now call
process.exit(1)directly (e.g., on seeding failure or startup errors), which can be surprising in a reusable package; consider surfacing errors to the caller and letting the top-level app decide when to exit.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `startMockMongoDB` helper no longer exposes a disposer or hooks into process shutdown signals, so there’s currently no clean way to stop the in-memory replica set; consider returning the `replicaSet` (or a stop function) and wiring it into SIGINT/SIGTERM handling as before.
- The `while (true)` loop that waits for `collectionsToSeed` has no timeout or backoff and could hang the process indefinitely if collections never appear; adding a maximum wait duration and clearer error reporting would make failures easier to diagnose.
- Several code paths in the seedwork now call `process.exit(1)` directly (e.g., on seeding failure or startup errors), which can be surprising in a reusable package; consider surfacing errors to the caller and letting the top-level app decide when to exit.
## Individual Comments
### Comment 1
<location path="apps/server-mongodb-memory-mock/src/seed/seed.ts" line_range="25-34" />
<code_context>
+ await connection.collection('users').insertMany(users);
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider making seeding idempotent or handling duplicate-key errors for repeated runs.
Because `insertMany` uses deterministic `_id` values, rerunning this seeding against the same DB will raise duplicate-key errors. To avoid that, consider clearing the collections first (e.g. `deleteMany({})`), using `ordered: false` and tolerating duplicate errors, or upserting by `_id` so the seeding is idempotent.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Introduce a seedable in-memory MongoDB server and populate it with initial OCOM domain data for verification workflows.
New Features:
Enhancements:
Build:
Documentation:
Tests:
Chores: