Fly.Postgres (Fly Postgres v0.3.4) 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.
Link to this section Summary
Functions
Rewrite the database config based on the runtime environment.
Returns the Repo module used by the Tracker 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.
Compute the database url to use for this app given the current configuration and runtime environment.
Rewrite the :url
value to include DNS helpers of "top1.nearest.of" to find
the closes database to target. If the host already contains that, leave it
unchanged. If it is missing, add it and return the updated the url in the
config. Raise an exception if the no URL set in the config.
Rewrite the :url
value to target the Postgres replica port of 5433.
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.
Generate and log "verbose" log messages only if enabled.
Generate and log "verbose" log messages only if running on a remote (not-primary region) and verbose logging is enabled.
Link to this section Types
Specs
env() :: :prod | :dev | :test
Link to this section Functions
Specs
Rewrite the database config based on the runtime environment.
This does not make changes when running a dev or test build.
Returns the Repo module used by the Tracker that is not the wrapped version. Used for making direct writable calls.
Example
Application is used to configure the tracker.
# Given Application config like this:
{Fly.Postgres.LSN.Tracker, repo: MyApp.Repo.Local}
Fly.Postgres()
#=> MyApp.Repo.Local
Fly.Postgres(tracker: Fly.Postgres.LSN.Tracker)
#=> MyApp.Repo.Local
# Given Application config like this:
{Fly.Postgres.LSN.Tracker, repo: MyApp.Repo.Local_1, name: :repo_tracker_1},
{Fly.Postgres.LSN.Tracker, repo: MyApp.Repo.Local_2, name: :repo_tracker_2},
Fly.Postgres(tracker: :repo_tracker_1)
#=> MyApp.Repo.Local_1
Fly.Postgres(tracker: :repo_tracker_2)
#=> MyApp.Repo.Local_2
Specs
make_connection_read_only!(DBConnection.t()) :: :ok | no_return()
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
Compute the database url to use for this app given the current configuration and runtime environment.
Specs
Rewrite the :url
value to include DNS helpers of "top1.nearest.of" to find
the closes database to target. If the host already contains that, leave it
unchanged. If it is missing, add it and return the updated the url in the
config. Raise an exception if the no URL set in the config.
Specs
Rewrite the :url
value to target the Postgres replica port of 5433.
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.
Options
:tracker
- The name of the tracker to wait on for replication tracking.:rpc_timeout
- Timeout duration to wait for RPC call to complete:replication_timeout
- Timeout duration to wait for replication to complete.
Generate and log "verbose" log messages only if enabled.
Generate and log "verbose" log messages only if running on a remote (not-primary region) and verbose logging is enabled.