View Source DbInfo (DbInfo v0.1.0)
Inspired by Vlado's gem.
DbInfo
Add dashboard access for development-only usage
Once installed, update your router's configuration to forward requests to a DbInfo with a unique name
of your choosing:
# lib/my_app_web/router.ex
use MyAppWeb, :router
import DbInfo.Router
...
if Mix.env() == :dev do
scope "/" do
pipe_through :browser
dbinfo "/dbinfo"
end
end
# config/config.exs
config :db_info, :app, :your_phoenix_app_name
This is all. Run mix phx.server
and access the "/dbinfo".
Extra: Add dashboard access on all environments (including production)
If you want to use the DbInfo in production, you should put it behind some authentication and allow only admins to access it. If your application does not have an admins-only section yet, you can use Plug.BasicAuth
to set up some basic authentication as long as you are also using SSL (which you should anyway):
# lib/my_app_web/router.ex
use MyAppWeb, :router
import DbInfo.Router
...
pipeline :admins_only do
plug :admin_basic_auth
end
scope "/" do
pipe_through [:browser, :admins_only]
dbinfo "/dbinfo"
end
defp admin_basic_auth(conn, _opts) do
username = System.fetch_env!("AUTH_USERNAME")
password = System.fetch_env!("AUTH_PASSWORD")
Plug.BasicAuth.basic_auth(conn, username: username, password: password)
end
Installation
If available in Hex, the package can be installed
by adding db_info
to your list of dependencies in mix.exs
:
def deps do
[
{:db_info, "~> 0.1.0"}
]
end
Troubleshooting
Dependency errors could be solved using following:
def deps do
[
{:ecto, "~> your_version", override: :true},
{:phoenix, "~> your_version", override: true},
{:phoenix_html, "~> your_version", override: :true}
]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/db_info.