From 01afb28af2b6ed1903f73293017ee61fb8cb8994 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Wed, 3 Jul 2019 13:00:27 +0100 Subject: [PATCH 1/5] Release v0.6.0 --- .gitignore | 1 + mix.lock | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 2c84b98..922279a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ erl_crash.dump *.ez +.elixir_ls diff --git a/mix.lock b/mix.lock index 055ae03..df796ba 100644 --- a/mix.lock +++ b/mix.lock @@ -1,20 +1,20 @@ %{ - "commanded": {:hex, :commanded, "0.19.0", "c0e90cfe8212ae076cd67c225dcb83547e3da267ea669fd9133f09c81c052d2c", [:mix], [{:elixir_uuid, "~> 1.2", [hex: :elixir_uuid, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: true]}], "hexpm"}, + "commanded": {:hex, :commanded, "0.19.1", "783eaa1e4213d6fd2e34cd10cf0742b06c049021db0c75e2ebd89bddd4181685", [:mix], [{:elixir_uuid, "~> 1.2", [hex: :elixir_uuid, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: true]}], "hexpm"}, "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"}, - "db_connection": {:hex, :db_connection, "2.1.0", "122e2f62c4906bf2e49554f1e64db5030c19229aa40935f33088e7d543aa79d0", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"}, + "db_connection": {:hex, :db_connection, "2.1.1", "a51e8a2ee54ef2ae6ec41a668c85787ed40cb8944928c191280fe34c15b76ae5", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"}, "decimal": {:hex, :decimal, "1.8.0", "ca462e0d885f09a1c5a342dbd7c1dcf27ea63548c65a65e67334f4b61803822e", [:mix], [], "hexpm"}, - "earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm"}, + "earmark": {:hex, :earmark, "1.4.0", "397e750b879df18198afc66505ca87ecf6a96645545585899f6185178433cc09", [:mix], [], "hexpm"}, "elixir_uuid": {:hex, :elixir_uuid, "1.2.0", "ff26e938f95830b1db152cb6e594d711c10c02c6391236900ddd070a6b01271d", [:mix], [], "hexpm"}, "eventstore": {:hex, :eventstore, "0.17.0", "c4e5a1d392756e7d592af993c5316072a4b0c1582ce8e0604a589ccb8a1797f5", [:mix], [{:elixir_uuid, "~> 1.2", [hex: :elixir_uuid, repo: "hexpm", optional: false]}, {:fsm, "~> 0.3", [hex: :fsm, repo: "hexpm", optional: false]}, {:gen_stage, "~> 0.14", [hex: :gen_stage, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14", [hex: :postgrex, repo: "hexpm", optional: false]}], "hexpm"}, - "ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"}, + "ex_doc": {:hex, :ex_doc, "0.21.2", "caca5bc28ed7b3bdc0b662f8afe2bee1eedb5c3cf7b322feeeb7c6ebbde089d6", [:mix], [{:earmark, "~> 1.3.3 or ~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"}, "file_system": {:hex, :file_system, "0.2.7", "e6f7f155970975789f26e77b8b8d8ab084c59844d8ecfaf58cbda31c494d14aa", [:mix], [], "hexpm"}, "fsm": {:hex, :fsm, "0.3.1", "087aa9b02779a84320dc7a2d8464452b5308e29877921b2bde81cdba32a12390", [:mix], [], "hexpm"}, "gen_stage": {:hex, :gen_stage, "0.14.2", "6a2a578a510c5bfca8a45e6b27552f613b41cf584b58210f017088d3d17d0b14", [:mix], [], "hexpm"}, "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"}, - "makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"}, + "makeup": {:hex, :makeup, "1.0.0", "671df94cf5a594b739ce03b0d0316aa64312cee2574b6a44becb83cd90fb05dc", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.14.0", "cf8b7c66ad1cff4c14679698d532f0b5d45a3968ffbcbfd590339cb57742f1ae", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"}, "mix_test_watch": {:hex, :mix_test_watch, "0.9.0", "c72132a6071261893518fa08e121e911c9358713f62794a90c95db59042af375", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm"}, "mox": {:hex, :mox, "0.5.1", "f86bb36026aac1e6f924a4b6d024b05e9adbed5c63e8daa069bd66fb3292165b", [:mix], [], "hexpm"}, - "nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"}, - "postgrex": {:hex, :postgrex, "0.14.3", "5754dee2fdf6e9e508cbf49ab138df964278700b764177e8f3871e658b345a1e", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"}, + "nimble_parsec": {:hex, :nimble_parsec, "0.5.1", "c90796ecee0289dbb5ad16d3ad06f957b0cd1199769641c961cfe0b97db190e0", [:mix], [], "hexpm"}, + "postgrex": {:hex, :postgrex, "0.15.0", "dd5349161019caeea93efa42f9b22f9d79995c3a86bdffb796427b4c9863b0f0", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"}, } From 73e3b746c57876783d206a5c74548cb18e2148be Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Thu, 12 Sep 2019 12:48:26 +0100 Subject: [PATCH 2/5] Support Commanded multi-app --- config/test.exs | 2 +- lib/event_store_adapter.ex | 103 +++++++++++++++++------- mix.exs | 10 ++- mix.lock | 4 +- test/event_store/append_events_test.exs | 2 +- test/event_store/snapshot_test.exs | 2 +- test/event_store/subscription_test.exs | 2 +- test/support/event_store_application.ex | 8 ++ test/support/storage.ex | 12 +-- test/support/test_event_store.ex | 3 + 10 files changed, 103 insertions(+), 45 deletions(-) create mode 100644 test/support/event_store_application.ex create mode 100644 test/support/test_event_store.ex diff --git a/config/test.exs b/config/test.exs index be33d12..ca07341 100644 --- a/config/test.exs +++ b/config/test.exs @@ -9,7 +9,7 @@ config :commanded, assert_receive_event_timeout: 1_000, refute_receive_event_timeout: 1_000 -config :eventstore, EventStore.Storage, +config :commanded_eventstore_adapter, TestEventStore, serializer: Commanded.Serialization.JsonSerializer, username: "postgres", password: "postgres", diff --git a/lib/event_store_adapter.ex b/lib/event_store_adapter.ex index a1db010..6bb4d35 100644 --- a/lib/event_store_adapter.ex +++ b/lib/event_store_adapter.ex @@ -1,7 +1,6 @@ defmodule Commanded.EventStore.Adapters.EventStore do @moduledoc """ - [EventStore](https://github.com/commanded/eventstore) adapter for - [Commanded](https://github.com/commanded/commanded). + EventStore adapter for Commanded. """ alias Commanded.EventStore.Adapters.EventStore.Mapper @@ -11,11 +10,19 @@ defmodule Commanded.EventStore.Adapters.EventStore do @all_stream "$all" @impl Commanded.EventStore - def child_spec, do: [] + def child_spec(event_store, config) do + event_store = get_event_store({event_store, config}) + + verify_event_store!(event_store) + + [event_store] + end @impl Commanded.EventStore - def append_to_stream(stream_uuid, expected_version, events) do - EventStore.append_to_stream( + def append_to_stream(event_store, stream_uuid, expected_version, events) do + event_store = get_event_store(event_store) + + event_store.append_to_stream( stream_uuid, expected_version, Enum.map(events, &Mapper.to_event_data/1) @@ -23,24 +30,29 @@ defmodule Commanded.EventStore.Adapters.EventStore do end @impl Commanded.EventStore - def stream_forward(stream_uuid, start_version \\ 0, read_batch_size \\ 1_000) do - case EventStore.stream_forward(stream_uuid, start_version, read_batch_size) do + def stream_forward(event_store, stream_uuid, start_version \\ 0, read_batch_size \\ 1_000) do + event_store = get_event_store(event_store) + + case event_store.stream_forward(stream_uuid, start_version, read_batch_size) do {:error, error} -> {:error, error} stream -> Stream.map(stream, &Mapper.from_recorded_event/1) end end @impl Commanded.EventStore - def subscribe(:all), do: subscribe(@all_stream) + def subscribe(event_store, :all), do: subscribe(event_store, @all_stream) @impl Commanded.EventStore - def subscribe(stream_uuid) do - EventStore.subscribe(stream_uuid, mapper: &Mapper.from_recorded_event/1) + def subscribe(event_store, stream_uuid) do + event_store = get_event_store(event_store) + event_store.subscribe(stream_uuid, mapper: &Mapper.from_recorded_event/1) end @impl Commanded.EventStore - def subscribe_to(:all, subscription_name, subscriber, start_from) do - EventStore.subscribe_to_all_streams( + def subscribe_to(event_store, :all, subscription_name, subscriber, start_from) do + event_store = get_event_store(event_store) + + event_store.subscribe_to_all_streams( subscription_name, subscriber, subscription_options(start_from) @@ -48,8 +60,10 @@ defmodule Commanded.EventStore.Adapters.EventStore do end @impl Commanded.EventStore - def subscribe_to(stream_uuid, subscription_name, subscriber, start_from) do - EventStore.subscribe_to_stream( + def subscribe_to(event_store, stream_uuid, subscription_name, subscriber, start_from) do + event_store = get_event_store(event_store) + + event_store.subscribe_to_stream( stream_uuid, subscription_name, subscriber, @@ -58,44 +72,51 @@ defmodule Commanded.EventStore.Adapters.EventStore do end @impl Commanded.EventStore - def ack_event(subscription, %Commanded.EventStore.RecordedEvent{} = event) do + def ack_event(event_store, subscription, %Commanded.EventStore.RecordedEvent{} = event) do %Commanded.EventStore.RecordedEvent{event_number: event_number} = event - EventStore.ack(subscription, event_number) + event_store = get_event_store(event_store) + event_store.ack(subscription, event_number) end @impl Commanded.EventStore - def unsubscribe(subscription) do + def unsubscribe(_event_store, subscription) do EventStore.Subscriptions.Subscription.unsubscribe(subscription) end @impl Commanded.EventStore - def delete_subscription(:all, subscription_name) do - EventStore.delete_subscription(@all_stream, subscription_name) + def delete_subscription(event_store, :all, subscription_name) do + event_store = get_event_store(event_store) + event_store.delete_subscription(@all_stream, subscription_name) end @impl Commanded.EventStore - def delete_subscription(stream_uuid, subscription_name) do - EventStore.delete_subscription(stream_uuid, subscription_name) + def delete_subscription(event_store, stream_uuid, subscription_name) do + event_store.delete_subscription(stream_uuid, subscription_name) end @impl Commanded.EventStore - def read_snapshot(source_uuid) do - with {:ok, snapshot_data} <- EventStore.read_snapshot(source_uuid) do + def read_snapshot(event_store, source_uuid) do + event_store = get_event_store(event_store) + + with {:ok, snapshot_data} <- event_store.read_snapshot(source_uuid) do {:ok, Mapper.from_snapshot_data(snapshot_data)} end end @impl Commanded.EventStore - def record_snapshot(%Commanded.EventStore.SnapshotData{} = snapshot) do + def record_snapshot(event_store, %Commanded.EventStore.SnapshotData{} = snapshot) do + event_store = get_event_store(event_store) + snapshot |> Mapper.to_snapshot_data() - |> EventStore.record_snapshot() + |> event_store.record_snapshot() end @impl Commanded.EventStore - def delete_snapshot(source_uuid) do - EventStore.delete_snapshot(source_uuid) + def delete_snapshot(event_store, source_uuid) do + event_store = get_event_store(event_store) + event_store.delete_snapshot(source_uuid) end defp subscription_options(start_from) do @@ -104,4 +125,32 @@ defmodule Commanded.EventStore.Adapters.EventStore do mapper: &Mapper.from_recorded_event/1 ] end + + defp get_event_store({_event_store, config}), do: Keyword.get(config, :event_store) + + defp verify_event_store!(event_store) do + unless event_store do + raise ArgumentError, + "missing :event_store option for event store adapter in application" + end + + unless Code.ensure_compiled?(event_store) do + raise ArgumentError, + "event store #{inspect(event_store)} was not compiled, " <> + "ensure it is correct and it is included as a project dependency" + end + + unless implements?(event_store, EventStore) do + raise ArgumentError, + "module #{inspect(event_store)} is not an EventStore, " <> + "ensure you pass an event store module to the :event_store config in application" + end + end + + # Returns `true` if module implements behaviour. + defp implements?(module, behaviour) do + behaviours = Keyword.take(module.__info__(:attributes), [:behaviour]) + + [behaviour] in Keyword.values(behaviours) + end end diff --git a/mix.exs b/mix.exs index 7c2563f..6aafb3d 100644 --- a/mix.exs +++ b/mix.exs @@ -38,8 +38,11 @@ defmodule Commanded.EventStore.Adapters.EventStore.Mixfile do defp deps do [ - {:commanded, ">= 0.19.0", runtime: Mix.env() == :test}, - {:eventstore, ">= 0.17.0"}, + # {:commanded, ">= 0.19.0", runtime: Mix.env() == :test}, + {:commanded, + github: "commanded/commanded", branch: "feature/multi-app", runtime: Mix.env() == :test}, + # {:eventstore, ">= 0.17.0"}, + {:eventstore, github: "commanded/eventstore"}, # Optional dependencies {:jason, "~> 1.1", optional: true}, @@ -76,8 +79,7 @@ defmodule Commanded.EventStore.Adapters.EventStore.Mixfile do maintainers: ["Ben Smith"], licenses: ["MIT"], links: %{ - "GitHub" => "https://github.com/commanded/commanded-eventstore-adapter", - "Docs" => "https://hexdocs.pm/commanded_eventstore_adapter/" + "GitHub" => "https://github.com/commanded/commanded-eventstore-adapter" } ] end diff --git a/mix.lock b/mix.lock index df796ba..b09ba5c 100644 --- a/mix.lock +++ b/mix.lock @@ -1,11 +1,11 @@ %{ - "commanded": {:hex, :commanded, "0.19.1", "783eaa1e4213d6fd2e34cd10cf0742b06c049021db0c75e2ebd89bddd4181685", [:mix], [{:elixir_uuid, "~> 1.2", [hex: :elixir_uuid, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: true]}], "hexpm"}, + "commanded": {:git, "https://github.com/commanded/commanded.git", "f182de796825bb800484c084a868952f4072d4b9", [branch: "feature/multi-app"]}, "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"}, "db_connection": {:hex, :db_connection, "2.1.1", "a51e8a2ee54ef2ae6ec41a668c85787ed40cb8944928c191280fe34c15b76ae5", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"}, "decimal": {:hex, :decimal, "1.8.0", "ca462e0d885f09a1c5a342dbd7c1dcf27ea63548c65a65e67334f4b61803822e", [:mix], [], "hexpm"}, "earmark": {:hex, :earmark, "1.4.0", "397e750b879df18198afc66505ca87ecf6a96645545585899f6185178433cc09", [:mix], [], "hexpm"}, "elixir_uuid": {:hex, :elixir_uuid, "1.2.0", "ff26e938f95830b1db152cb6e594d711c10c02c6391236900ddd070a6b01271d", [:mix], [], "hexpm"}, - "eventstore": {:hex, :eventstore, "0.17.0", "c4e5a1d392756e7d592af993c5316072a4b0c1582ce8e0604a589ccb8a1797f5", [:mix], [{:elixir_uuid, "~> 1.2", [hex: :elixir_uuid, repo: "hexpm", optional: false]}, {:fsm, "~> 0.3", [hex: :fsm, repo: "hexpm", optional: false]}, {:gen_stage, "~> 0.14", [hex: :gen_stage, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14", [hex: :postgrex, repo: "hexpm", optional: false]}], "hexpm"}, + "eventstore": {:git, "https://github.com/commanded/eventstore.git", "2a6725fcb4c398d81a74455b6077901189b75386", []}, "ex_doc": {:hex, :ex_doc, "0.21.2", "caca5bc28ed7b3bdc0b662f8afe2bee1eedb5c3cf7b322feeeb7c6ebbde089d6", [:mix], [{:earmark, "~> 1.3.3 or ~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"}, "file_system": {:hex, :file_system, "0.2.7", "e6f7f155970975789f26e77b8b8d8ab084c59844d8ecfaf58cbda31c494d14aa", [:mix], [], "hexpm"}, "fsm": {:hex, :fsm, "0.3.1", "087aa9b02779a84320dc7a2d8464452b5308e29877921b2bde81cdba32a12390", [:mix], [], "hexpm"}, diff --git a/test/event_store/append_events_test.exs b/test/event_store/append_events_test.exs index 8067152..daded36 100644 --- a/test/event_store/append_events_test.exs +++ b/test/event_store/append_events_test.exs @@ -1,5 +1,5 @@ defmodule Commanded.EventStore.Adapters.EventStore.AppendEventsTest do - use Commanded.EventStore.AppendEventsTestCase + use Commanded.EventStore.AppendEventsTestCase, application: EventStoreApplication alias Commanded.EventStore.Adapters.EventStore.Storage diff --git a/test/event_store/snapshot_test.exs b/test/event_store/snapshot_test.exs index 3383d89..78dfeea 100644 --- a/test/event_store/snapshot_test.exs +++ b/test/event_store/snapshot_test.exs @@ -1,5 +1,5 @@ defmodule Commanded.EventStore.Adapters.EventStore.SnapshotTest do - use Commanded.EventStore.SnapshotTestCase + use Commanded.EventStore.SnapshotTestCase, application: EventStoreApplication alias Commanded.EventStore.Adapters.EventStore.Storage diff --git a/test/event_store/subscription_test.exs b/test/event_store/subscription_test.exs index a09baa0..0f7e6ff 100644 --- a/test/event_store/subscription_test.exs +++ b/test/event_store/subscription_test.exs @@ -1,5 +1,5 @@ defmodule Commanded.EventStore.Adapters.EventStore.SubscriptionTest do - use Commanded.EventStore.SubscriptionTestCase + use Commanded.EventStore.SubscriptionTestCase, application: EventStoreApplication alias Commanded.EventStore.Adapters.EventStore.Storage diff --git a/test/support/event_store_application.ex b/test/support/event_store_application.ex new file mode 100644 index 0000000..bdd4d0d --- /dev/null +++ b/test/support/event_store_application.ex @@ -0,0 +1,8 @@ +defmodule EventStoreApplication do + use Commanded.Application, + otp_app: :commanded_eventstore_adapter, + event_store: [ + adapter: Commanded.EventStore.Adapters.EventStore, + event_store: TestEventStore + ] +end diff --git a/test/support/storage.ex b/test/support/storage.ex index cc27fbf..e65f1e1 100644 --- a/test/support/storage.ex +++ b/test/support/storage.ex @@ -3,16 +3,12 @@ defmodule Commanded.EventStore.Adapters.EventStore.Storage do alias EventStore.Storage.Initializer def connect do - postgrex_config = Config.parsed() |> Config.default_postgrex_opts() + postgrex_config = + Config.parsed(TestEventStore, :commanded_eventstore_adapter) + |> Config.default_postgrex_opts() Postgrex.start_link(postgrex_config) end - def reset!(conn) do - Application.stop(:eventstore) - - Initializer.reset!(conn) - - Application.ensure_all_started(:eventstore) - end + def reset!(conn), do: Initializer.reset!(conn) end diff --git a/test/support/test_event_store.ex b/test/support/test_event_store.ex new file mode 100644 index 0000000..9bf9dd7 --- /dev/null +++ b/test/support/test_event_store.ex @@ -0,0 +1,3 @@ +defmodule TestEventStore do + use EventStore, otp_app: :commanded_eventstore_adapter +end From 964c7eabb2f5a549e84dca22921dfa2a122ed42d Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Thu, 12 Sep 2019 17:42:28 +0100 Subject: [PATCH 3/5] Include #4 in CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52aead8..201d807 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Next release + +- Support multiple Commanded apps ([#4](https://github.com/commanded/commanded-eventstore-adapter/pull/4/files)). + ## 0.6.0 ### Enhancements From f1340c0c6c0be8c339ea83df21aae954304e7b36 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Thu, 12 Sep 2019 17:52:35 +0100 Subject: [PATCH 4/5] Document event store setup for a Commanded app --- README.md | 36 ++++++++++++++++++++++-------------- config/test.exs | 2 ++ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d720921..1252afc 100644 --- a/README.md +++ b/README.md @@ -20,38 +20,46 @@ The package can be installed from hex as follows. end ``` -2. Include `:eventstore` in the list of extra applications to start in `mix.exs`: +2. Create an event store for your application: ```elixir - def application do - [ - extra_applications: [ - :logger, - :eventstore, - ], - ] + defmodule MyApp.EventStore do + use EventStore, otp_app: :my_app end ``` -3. Configure Commanded to use the `Commanded.EventStore.Adapters.EventStore` adapter: +3. Define and configure your Commanded application to use the `Commanded.EventStore.Adapters.EventStore` adapter and event store module: ```elixir - config :commanded, - event_store_adapter: Commanded.EventStore.Adapters.EventStore + defmodule MyApp.Application do + use Commanded.Application, + otp_app: :my_app, + event_store: [ + adapter: Commanded.EventStore.Adapters.EventStore, + event_store: MyApp.EventStore + ] + end ``` 4. Configure the `eventstore` in each environment's mix config file (e.g. `config/dev.exs`), specifying usage of the included JSON serializer: ```elixir - config :eventstore, EventStore.Storage, - serializer: Commanded.Serialization.JsonSerializer, + config :my_app, MyApp.EventStore, + serializer: EventStore.JsonSerializer, username: "postgres", password: "postgres", - database: "eventstore_dev", + database: "eventstore", hostname: "localhost", pool_size: 10 ``` +5. Add your event store to `config/config.exs` to make it easier to use the event store mix tasks: + + ```elixir + # config/config.exs + config :my_app, event_stores: [MyApp.EventStore] + ``` + 5. Create the `eventstore` database and tables using the `mix` task: ```console diff --git a/config/test.exs b/config/test.exs index ca07341..6481df7 100644 --- a/config/test.exs +++ b/config/test.exs @@ -9,6 +9,8 @@ config :commanded, assert_receive_event_timeout: 1_000, refute_receive_event_timeout: 1_000 +config :commanded_eventstore_adapter, event_stores: [TestEventStore] + config :commanded_eventstore_adapter, TestEventStore, serializer: Commanded.Serialization.JsonSerializer, username: "postgres", From 9726f2bed67b2f9f72d089b6d09949f28fddcda9 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Thu, 12 Sep 2019 20:04:25 +0100 Subject: [PATCH 5/5] Include getting started guide in Hex docs --- LICENSE | 20 +++++++++---- README.md | 60 ++++---------------------------------- guides/Getting Started.md | 57 ++++++++++++++++++++++++++++++++++++ lib/event_store_adapter.ex | 4 +-- mix.exs | 17 ++++++----- mix.lock | 2 +- 6 files changed, 89 insertions(+), 71 deletions(-) create mode 100644 guides/Getting Started.md diff --git a/LICENSE b/LICENSE index 2165cc1..ce0599e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,8 +1,18 @@ -The MIT License (MIT) -Copyright (c) 2017 Ben Smith (ben@10consulting.com) +The MIT License (MIT) Copyright (c) 2017 Ben Smith (ben@10consulting.com) -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 1252afc..31d2338 100644 --- a/README.md +++ b/README.md @@ -8,60 +8,12 @@ MIT License [![Build Status](https://travis-ci.com/commanded/commanded-eventstore-adapter.svg?branch=master)](https://travis-ci.com/commanded/commanded-eventstore-adapter) -## Getting started +--- -The package can be installed from hex as follows. +> This README and the following guides follow the `master` branch which may not be the currently published version. +> +> [Read the documentation for the latest published version of Commanded EventStore adapter on Hex](https://hexdocs.pm/commanded_eventstore_adapter/). -1. Add `commanded_eventstore_adapter` to your list of dependencies in `mix.exs`: +### Overview - ```elixir - def deps do - [{:commanded_eventstore_adapter, "~> 0.6"}] - end - ``` - -2. Create an event store for your application: - - ```elixir - defmodule MyApp.EventStore do - use EventStore, otp_app: :my_app - end - ``` - -3. Define and configure your Commanded application to use the `Commanded.EventStore.Adapters.EventStore` adapter and event store module: - - ```elixir - defmodule MyApp.Application do - use Commanded.Application, - otp_app: :my_app, - event_store: [ - adapter: Commanded.EventStore.Adapters.EventStore, - event_store: MyApp.EventStore - ] - end - ``` - -4. Configure the `eventstore` in each environment's mix config file (e.g. `config/dev.exs`), specifying usage of the included JSON serializer: - - ```elixir - config :my_app, MyApp.EventStore, - serializer: EventStore.JsonSerializer, - username: "postgres", - password: "postgres", - database: "eventstore", - hostname: "localhost", - pool_size: 10 - ``` - -5. Add your event store to `config/config.exs` to make it easier to use the event store mix tasks: - - ```elixir - # config/config.exs - config :my_app, event_stores: [MyApp.EventStore] - ``` - -5. Create the `eventstore` database and tables using the `mix` task: - - ```console - $ mix do event_store.create, event_store.init - ``` +- [Getting started](guides/Getting%20Started.md) diff --git a/guides/Getting Started.md b/guides/Getting Started.md new file mode 100644 index 0000000..290dfab --- /dev/null +++ b/guides/Getting Started.md @@ -0,0 +1,57 @@ +# Getting started + +The package can be installed from hex as follows. + +1. Add `commanded_eventstore_adapter` to your list of dependencies in `mix.exs`: + + ```elixir + def deps do + [{:commanded_eventstore_adapter, "~> 0.6"}] + end + ``` + +2. Create an event store for your application: + + ```elixir + defmodule MyApp.EventStore do + use EventStore, otp_app: :my_app + end + ``` + +3. Define and configure your Commanded application to use the `Commanded.EventStore.Adapters.EventStore` adapter and your own event store module: + + ```elixir + defmodule MyApp.Application do + use Commanded.Application, + otp_app: :my_app, + event_store: [ + adapter: Commanded.EventStore.Adapters.EventStore, + event_store: MyApp.EventStore + ] + end + ``` + +4. Configure the event store in each environment's mix config file (e.g. `config/dev.exs`), specifying usage of the included JSON serializer: + + ```elixir + config :my_app, MyApp.EventStore, + serializer: Commanded.Serialization.JsonSerializer, + username: "postgres", + password: "postgres", + database: "eventstore_dev", + hostname: "localhost", + pool_size: 10 + ``` + +5. Add your event store to `config/config.exs` to make it easier to use the event store mix tasks: + + ```elixir + # config/config.exs + config :my_app, event_stores: [MyApp.EventStore] + ``` + +6. Create the `eventstore` database and tables using the `mix` task: + + ```console + $ mix do event_store.create, event_store.init + ``` diff --git a/lib/event_store_adapter.ex b/lib/event_store_adapter.ex index 6bb4d35..b819615 100644 --- a/lib/event_store_adapter.ex +++ b/lib/event_store_adapter.ex @@ -1,7 +1,5 @@ defmodule Commanded.EventStore.Adapters.EventStore do - @moduledoc """ - EventStore adapter for Commanded. - """ + @moduledoc false alias Commanded.EventStore.Adapters.EventStore.Mapper diff --git a/mix.exs b/mix.exs index 6aafb3d..fbb4da8 100644 --- a/mix.exs +++ b/mix.exs @@ -34,21 +34,18 @@ defmodule Commanded.EventStore.Adapters.EventStore.Mixfile do ] end - defp elixirc_paths(_), do: ["lib"] + defp elixirc_paths(_env), do: ["lib"] defp deps do [ - # {:commanded, ">= 0.19.0", runtime: Mix.env() == :test}, - {:commanded, - github: "commanded/commanded", branch: "feature/multi-app", runtime: Mix.env() == :test}, - # {:eventstore, ">= 0.17.0"}, + {:commanded, github: "commanded/commanded"}, {:eventstore, github: "commanded/eventstore"}, # Optional dependencies {:jason, "~> 1.1", optional: true}, # Build & test tools - {:ex_doc, "~> 0.20", only: :dev}, + {:ex_doc, "~> 0.21", only: :dev}, {:mix_test_watch, "~> 0.9", only: :dev}, {:mox, "~> 0.5", only: :test} ] @@ -62,9 +59,13 @@ defmodule Commanded.EventStore.Adapters.EventStore.Mixfile do defp docs do [ - main: "Commanded.EventStore.Adapters.EventStore", + main: "Getting-Started", canonical: "http://hexdocs.pm/commanded_eventstore_adapter", - source_ref: "v#{@version}" + source_ref: "v#{@version}", + extras: [ + {"guides/Getting Started.md", title: "EventStore adapter"}, + "CHANGELOG.md" + ] ] end diff --git a/mix.lock b/mix.lock index b09ba5c..b816b3a 100644 --- a/mix.lock +++ b/mix.lock @@ -1,5 +1,5 @@ %{ - "commanded": {:git, "https://github.com/commanded/commanded.git", "f182de796825bb800484c084a868952f4072d4b9", [branch: "feature/multi-app"]}, + "commanded": {:git, "https://github.com/commanded/commanded.git", "f635b692b28192a1fa1b67acac3dfd8d23883dc1", []}, "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"}, "db_connection": {:hex, :db_connection, "2.1.1", "a51e8a2ee54ef2ae6ec41a668c85787ed40cb8944928c191280fe34c15b76ae5", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"}, "decimal": {:hex, :decimal, "1.8.0", "ca462e0d885f09a1c5a342dbd7c1dcf27ea63548c65a65e67334f4b61803822e", [:mix], [], "hexpm"},