commanded / eventstore

Event store using PostgreSQL for persistence
MIT License
1.06k stars 146 forks source link

[Doc] Running mix tasks using Elixir releases #178

Closed slashdotdash closed 5 years ago

slashdotdash commented 5 years ago

The EventStore mix tasks, such as mix event_store.create, delegate the actual work to corresponding task modules defined inside EventStore (in lib/mix/tasks) so you can use them directly:

Mix releases support running one-off commands and using a helper module to define these commands, example below.

defmodule MyApp.ReleaseTasks do
  def init_event_store do
    {:ok, _} = Application.ensure_all_started(:postgrex)
    {:ok, _} = Application.ensure_all_started(:ssl)

    :ok = Application.load(:eventstore)

    config = EventStore.Config.parsed()

    EventStore.Tasks.Create.exec(config, [])
    EventStore.Tasks.Init.exec(config, [])
  end
end

Run a release task:

bin/RELEASE_NAME eval "MyApp.ReleaseTasks.init_event_store()"
norpan commented 4 years ago

Just wanted to note here that you now (version 1.0) have to do Your.EventStore.config() instead of EventStore.Config.parsed().