FlyMultiRegion (fly_multi_region v0.0.1)
Documentation for FlyMultiRegion
.
For setting up read-replica databases refer to Fly.io's documentation
Usage
Installation
The package can be installed by adding fly_multi_region
to your list of dependencies in mix.exs
:
def deps do
[
{:fly_multi_region, "~> 0.0.1"}
]
end
Configuration
If you're following the Fly.io guides then your database config will happen at runtime. Add the following to the runtime.exs
file:
config :fly_multi_region,
region: System.get_env("FLY_REGION"),
regions: ["nrt", "ord"],
url: System.get_env("DATABASE_URL"),
opts: [
socket_options: [:inet6],
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")
]
Parameters:
- region: generated by Fly.io by default
- regions: a list of replicas in your cluster
- url: database url
- opts: configuration options for Ecto
Supervision
Add FlyMultiRegion to your Application's supervision tree
As mentioned in Ecto's documentation for replica databases it's necessary to add any Repos to your supervision tree. With that in mind, make sure to add FlyMultiRegion
to your Application module (application.ex)
def start(_type, _args) do
children =
[
...,
FlyMultiRegion
]
...
Supervisor.start_link(children, opts)
end
Repo
Add the following to your projects main Repo module:
use FlyMultiRegion.Repo
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Returns replica Repo module name
Link to this section Functions
child_spec(init_arg)
Returns a specification to start this module under a supervisor.
See Supervisor
.
repo_module(region)
Returns replica Repo module name