Surgex.RepoHelpers (Surgex v6.0.1)

View Source

Tools for dynamic setup of Ecto repo opts.

NOTE: Deprecated in favor of Elixir 1.9 runtime configuration.

This module will be removed in a future version. Use Elixir 1.9+ runtime configuration with config/runtime.exs instead.

Migration Guide

Replace usage of this module with runtime configuration in config/runtime.exs:

# config/runtime.exs
import Config

if config_env() == :prod do
  config :my_app, MyApp.Repo,
    url: System.get_env("DATABASE_URL"),
    pool_size: String.to_integer(System.get_env("DATABASE_POOL_SIZE") || "10"),
    ssl: System.get_env("DATABASE_SSL") == "true"
end

Summary

Functions

Sets application_name to the value of APP_NAME env var.

Sets repo options from env vars starting with specified prefix.

Sets repo database pool size from specified env var.

Sets repo database pool size from specified env var only if Phoenix server is configured to run.

set_ssl(opts, env) deprecated

Sets repo database ssl enable from specified env var.

set_url(opts, env) deprecated

Sets repo database URL from specified env var.

Functions

set_application_name(opts)

This function is deprecated. Use Elixir 1.9+ runtime configuration (config/runtime.exs) instead.

Sets application_name to the value of APP_NAME env var.

set_opts(opts, env_prefix \\ :database)

This function is deprecated. Use Elixir 1.9+ runtime configuration (config/runtime.exs) instead.

Sets repo options from env vars starting with specified prefix.

Examples

iex> System.put_env("DATABASE_URL", "postgres://localhost")
iex> System.put_env("DATABASE_SERVER_POOL_SIZE", "30")
iex> System.put_env("DATABASE_SSL", "true")
iex> Application.put_env(:phoenix, :serve_endpoints, true)
iex>
iex> final_opts = Surgex.RepoHelpers.set_opts([])
iex>
iex> Keyword.get(final_opts, :url)
"postgres://localhost"
iex> Keyword.get(final_opts, :pool_size)
30
iex> Keyword.get(final_opts, :ssl)
true

set_pool_size(opts, env)

This function is deprecated. Use Elixir 1.9+ runtime configuration (config/runtime.exs) instead.

Sets repo database pool size from specified env var.

set_server_pool_size(opts, env)

This function is deprecated. Use Elixir 1.9+ runtime configuration (config/runtime.exs) instead.

Sets repo database pool size from specified env var only if Phoenix server is configured to run.

set_ssl(opts, env)

This function is deprecated. Use Elixir 1.9+ runtime configuration (config/runtime.exs) instead.

Sets repo database ssl enable from specified env var.

set_url(opts, env)

This function is deprecated. Use Elixir 1.9+ runtime configuration (config/runtime.exs) instead.

Sets repo database URL from specified env var.