DbOps (db_ops v0.1.1)

Copy Markdown View Source

Lightweight runtime db 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

Creates all databases associated with the application's Ecto repos.

Drops all databases associated with the application's Ecto repos.

Runs the database seed script.

Functions

create(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)"

drop(app, opts \\ [])

@spec drop(atom(), keyword()) :: :ok | {:error, :confirmation_required}

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")"

seed(app, seed_file \\ nil)

@spec seed(atom(), String.t() | nil) :: :ok | {:error, :seed_not_found}

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")"