Skip to content

Commit

Permalink
Move AggregateKeyNotUniqueError to Sequent::Core namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
erikrozendaal committed Jan 6, 2025
1 parent 9aa5cc9 commit 545d7f1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
20 changes: 20 additions & 0 deletions lib/sequent/core/aggregate_root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,26 @@ def to_s
"#{self.class.name}: #{@id}"
end

# Some aggregates represent a unique external entity (e.g. a
# user's email address or login name) and this uniqueness needs
# to be enforced. For each unique key the returned object should
# have an entry where the key of the entry describes the scope
# of the constraint (e.g. `user_email` or `login_name`) and the
# value represents the unique value. Values can be any JSON
# value (string, object, array, etc). Note that uniqueness is
# enforced across all aggregate types if the same scope is used.
#
# An `AggregateKeyNotUniqueError` is raised if a unique
# constrained is violated when committing the events to the
# database.
#
# Sample return value:
#
# ```
# {
# user_email: { email: '[email protected]' }
# }
# ```
def unique_keys
{}
end
Expand Down
6 changes: 3 additions & 3 deletions lib/sequent/core/event_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

module Sequent
module Core
class AggregateKeyNotUniqueError < RuntimeError
end

class EventStore
include Helpers::PgsqlHelpers
include SnapshotStore
Expand All @@ -18,9 +21,6 @@ class EventStore
class OptimisticLockingError < RuntimeError
end

class AggregateKeyNotUniqueError < RuntimeError
end

class DeserializeEventError < RuntimeError
attr_reader :event_hash

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/sequent/core/aggregate_repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def unique_keys
Sequent.aggregate_repository.add_aggregate(dummy2)

expect { Sequent.aggregate_repository.commit(DummyCommand.new) }
.to raise_error Sequent::Core::EventStore::AggregateKeyNotUniqueError
.to raise_error Sequent::Core::AggregateKeyNotUniqueError
end
end
end
Expand Down

0 comments on commit 545d7f1

Please sign in to comment.