Fly.Postgres (Fly Postgres v0.1.13)
View Source
Help Elixir applications more easily take advantage of distributed Elixir
applications using Ecto and PostgreSQL in a primary/replica configuration on
Fly.io.
Compute the database url to use for this app given the current configuration
and runtime environment.
Returns the Repo module used by the application that is not the wrapped
version. Used for making direct writable calls.
Function used to make the repository be read-only and error when creates,
updates, or deletes are attempted. This behaves like a read-only replica
which is helpful when modelling that setup locally in a dev environment.
Return the database url used for connecting to the primary database. This is
provided by the Fly.io platform when you have attached to a PostgreSQL
database. Stored as an ENV called DATABASE_URL
.
Return a database url used for connecting to a replica database. This makes
the assumption that there is a replica running in the region where the app
instance is running.
Execute the MFA (Module, Function, Arguments) on a node in the primary region.
This waits for the data to be replicated to the current node before continuing
on.
Specs
Compute the database url to use for this app given the current configuration
and runtime environment.
Returns the Repo module used by the application that is not the wrapped
version. Used for making direct writable calls.
Example
Requires using application to configure.
# Configure database repository
config :fly_postgres, :local_repo, MyApp.Repo.Local
Specs
Function used to make the repository be read-only and error when creates,
updates, or deletes are attempted. This behaves like a read-only replica
which is helpful when modelling that setup locally in a dev environment.
Example
In your config/dev.exs
,
# Configure your database
config :my_app, MyApp.Repo.Local,
username: "postgres",
password: "postgres",
database: "my_db_dev",
hostname: "localhost",
show_sensitive_data_on_connection_error: true,
# Forcing the repo to be R/O locally for dev testing
after_connect: {Fly, :make_connection_read_only!, []},
pool_size: 10
Specs
Return the database url used for connecting to the primary database. This is
provided by the Fly.io platform when you have attached to a PostgreSQL
database. Stored as an ENV called DATABASE_URL
.
If rewrite_db_url
is disabled, a nil
is returned for the url.
Specs
Return a database url used for connecting to a replica database. This makes
the assumption that there is a replica running in the region where the app
instance is running.
If rewrite_db_url
is disabled, a nil
is returned for the url.
Execute the MFA (Module, Function, Arguments) on a node in the primary region.
This waits for the data to be replicated to the current node before continuing
on.
This presumes the primary region has direct access to a writable primary
Postgres database.