Lightweight runtime database management utility for Elixir/Ecto Releases.
Designed to be invoked via eval on release binaries in production/staging environments
where Mix is not installed.
Summary
Functions
Returns the configuration for all Ecto repos associated with the application.
Creates all databases associated with the application's Ecto repos.
Drops all databases associated with the application's Ecto repos.
Returns a PostgreSQL connection URL that is safe to pass to psql in production.
Runs the database seed script.
Checks the database status for all Ecto repos associated with the application.
Functions
Returns the configuration for all Ecto repos associated with the application.
Examples
DbOps.config()
DbOps.config(:my_app)
@spec create(atom()) :: :ok
Creates all databases associated with the application's Ecto repos.
Examples
# In release execution:
# ./bin/my_app eval "DbOps.create(:my_app)"
Drops all databases associated with the application's Ecto repos.
Requires explicit confirmation parameter to prevent accidental deletion in production.
Examples
# Refused execution:
# ./bin/my_app eval "DbOps.drop(:my_app)"
# Confirmed execution:
# ./bin/my_app eval "DbOps.drop(:my_app, confirm: "YES_DELETE_DATABASE")"
Returns a PostgreSQL connection URL that is safe to pass to psql in production.
This method accepts the application's repo config or the DATABASE_URL value from
the runtime environment and normalizes it to a stable postgres://... URL.
Examples
DbOps.psql_url(:my_app)
DbOps.psql_url(MyApp.Repo.config())
DbOps.psql_url("ecto://postgres:postgres@localhost/ecto_simple?ssl=true&pool_size=10")
Runs the database seed script.
Defaults to priv/repo/seeds.exs inside the application's priv directory.
Examples
# ./bin/my_app eval "DbOps.seed(:my_app)"
# ./bin/my_app eval "DbOps.seed(:my_app, "priv/repo/custom_seeds.exs")"
@spec status(atom()) :: :ok
Checks the database status for all Ecto repos associated with the application.
Examples
# ./bin/my_app eval "DbOps.status()"
# ./bin/my_app eval "DbOps.status(:my_app)"