Comments (3)
For dynamic event stores you cannot use the Mix tasks provided by the event store library. Instead you will need to create your own Mix task - or release tasks module for deployment - and manually call the event store tasks to create, init, and migrate the separate event store schemas.
You need to include the dynamic schema in the event store's config:
alias EventStore.Tasks.{Create, Init, Migrate}
alias MyApp.Commanded.EventStore
for schema <- ["eventstore_default", "eventstore_other"] do
config = EventStore.config() |> Keyword.merge(pool_size: 1, schema: schema)
Create.exec(config, quiet: true)
Init.exec(config, quiet: true)
Migrate.exec(config, quiet: true)
end
For deployment using a release tasks module see the Phoenix deploying with releases documentation where they have an example of Ecto migrations and custom commands. Example show below.
defmodule MyApp.Release do
alias EventStore.Tasks.{Create, Init, Migrate}
alias MyApp.Commanded.EventStore
@app :my_app
def migrate do
load_app()
for schema <- ["eventstore_default", "eventstore_other"] do
config = EventStore.config() |> Keyword.merge(pool_size: 1, schema: schema)
Create.exec(config, quiet: true)
Init.exec(config, quiet: true)
Migrate.exec(config, quiet: true)
end
end
defp load_app do
Application.load(@app)
end
end
Then you'd run:
$ MIX_ENV=prod mix release
$ _build/prod/rel/my_app/bin/my_app eval "MyApp.Release.migrate"
from eventstore.
Worked like a charm, thank you!
from eventstore.
I think this information should be somewhere public, probably in the guides.
For anyone curious, here's what I modified my (autogenerated, as per the guide referred to above) releases module into for deployment using elixir releases
defmodule MyApp.Release do
@moduledoc """
Used for executing DB release tasks when run in production without Mix
installed.
"""
alias EventStore.Tasks.{Create, Init, Migrate}
@app :my_app
def migrate do
load_app()
for repo <- repos() do
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
end
end
def rollback(repo, version) do
load_app()
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
end
def setup_event_stores do
load_app()
for event_store <- event_stores() do
config = event_store.config()
Create.exec(config, quiet: true)
Init.exec(config, quiet: true)
Migrate.exec(config, quiet: true)
end
end
defp repos do
Application.fetch_env!(@app, :ecto_repos)
end
defp event_stores do
Application.fetch_env!(@app, :event_stores)
end
defp load_app do
Application.load(@app)
end
end
setup_event_stores/0
is the interesting function
Then I ran
$ MIX_ENV=prod mix release
$ _build/prod/rel/my_app/bin/my_app eval "MyApp.Release.migrate"
$ _build/prod/rel/my_app/bin/my_app eval "MyApp.Release.setup_event_stores"
from eventstore.
Related Issues (20)
- jsonb_serializer does not work because it tries to convet keys in json type data fields to atoms HOT 5
- Multi tenancy support HOT 4
- Unable to run `mix event_store.init` with existing database HOT 3
- Allow an `event_id` to be provided when appending events HOT 1
- Match Error Between event_store and Postgrex.Error HOT 1
- after disconnecting the server from the internet it shuts down the DB then the whole app
- is 1.4.0 to be published soon? HOT 1
- Can't reset store for testing HOT 3
- EventStore uses atom for :name - long lived system - atom exhaustion HOT 2
- Event stream table size limit? HOT 3
- Use configurable event store query timeout for subscription queries
- no function clause matching in EventStore.Storage.Appender.handle_response/1
- Unsupported query parameter `sslmode` HOT 9
- Dialyzer error when calling subscribe/2 with `name` option HOT 1
- using delete_stream HOT 2
- Perform unattended init and migration on application startup
- Event retention policy/pruning HOT 1
- can you give a concrete example of how to stream all events HOT 3
- Read events by event type HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eventstore.