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

Add custom collection names #407

Merged
merged 2 commits into from Jun 17, 2023

Conversation

totemcaf
Copy link

@totemcaf totemcaf commented May 11, 2023

Description

Let use a custom name for Outbox and Snapshots collections.

Affected Components

  • mongodb.Outbox
  • mongodb_v2.EventStore

Related Issues

None

Solution and Design

This is a replication of the available functionality to set event and streams collection names.

Added an Option to set the custom name:

  • outbox.WithCollectionNames
  • mongodb_v2.WithSnapshotCollectionName

The WithSnapshotCollectionName is added to kepp compatibility with exitent WithtCollectionName (and because I want to review if Snapshot should be part of this EventStore or should be another store).

Steps to test and verify

  1. Create an event store with custom name: NewEventStore(url, db, WithSnapshotCollectionName("foo"))

  2. Check in database the collection created is foo

  3. Create an outbox with custom name: NewOutbox(url, db, WithCollectionName("foo-outbox"))

  4. Check in database the collection created is foo-outbox

Add custom collection name for Snapshots
@coveralls
Copy link

coveralls commented May 29, 2023

Coverage Status

coverage: 67.237% (-0.4%) from 67.599% when pulling 337e2a3 on AltScore:feature/let-set-collection-names into 599169c on looplab:main.

eventstore/mongodb_v2/eventstore.go Show resolved Hide resolved
@@ -140,6 +125,62 @@ func TestWithCollectionNamesIntegration(t *testing.T) {
}
}

func TestWithSnapshotCollectionNamesIntegration(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Table-based tests would be useful here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, feel free to do it, or it can be done as part of a larger test overhaul in the future (nothing planned though).


// providing empty snapshot collection names should result in an error
_, err = NewEventStore(url, db,
WithSnapshotCollectionName(""),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if " " or similar is passed in? This could happen if the caller is dynamically forming the collection name and doesn't sufficiently check that it's not just pure whitespace.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, relates to your comment about trimming above. Feel free to add a test case for it, but I'll accept the PR without it too.

eventstore/mongodb_v2/eventstore.go Outdated Show resolved Hide resolved
Copy link
Member

@maxekman maxekman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice addition! Feel free to resolve what you want, I can merge when you are happy.

@totemcaf
Copy link
Author

totemcaf commented Jun 7, 2023

@maxekman I added an additional check for spaces.

@totemcaf
Copy link
Author

@maxekman fill free to merge

@maxekman maxekman merged commit ac3a972 into looplab:main Jun 17, 2023
5 checks passed
@maxekman
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants