Router macro for mounting the PgFlow Dashboard.
Usage
defmodule MyAppWeb.Router do
use MyAppWeb, :router
import PgFlowDashboard.Router
scope "/" do
pipe_through [:browser]
pgflow_dashboard "/pgflow",
repo: MyApp.Repo,
pubsub: MyApp.PubSub
end
endOptions
See PgFlowDashboard.Config for all available options.
Required:
:repo- The Ecto repository module:pubsub- The Phoenix.PubSub module
Optional:
:refresh_interval- Polling interval (default: 5000ms):time_zone- Time zone for timestamps (default: "UTC"):default_time_range- Default filter (default: :last_24h):max_grid_runs- Max runs in history grid (default: 50)
Summary
Functions
Derive the full base path by finding where the dashboard path appears
in the request URL. This handles outer scopes (e.g., "/admin/pgflow"
when pgflow_dashboard("/pgflow") is mounted inside scope "/admin").
Ensures optional dashboard dependencies are available before routes are mounted.
Mounts dashboard configuration into each PgFlowDashboard LiveView socket.
Generates routes for the PgFlow Dashboard.
Builds the LiveView session map used by PgFlowDashboard routes.
Functions
Derive the full base path by finding where the dashboard path appears
in the request URL. This handles outer scopes (e.g., "/admin/pgflow"
when pgflow_dashboard("/pgflow") is mounted inside scope "/admin").
@spec ensure_dashboard_dependencies!() :: :ok
Ensures optional dashboard dependencies are available before routes are mounted.
PgFlow can be used without PgFlowDashboard. When an application imports and
mounts pgflow_dashboard/2, the dashboard requires Phoenix LiveView,
LiveFilter, and Tz to be installed in the host project.
@spec on_mount(:mount_dashboard, map(), map(), Phoenix.LiveView.Socket.t()) :: {:cont, Phoenix.LiveView.Socket.t()}
Mounts dashboard configuration into each PgFlowDashboard LiveView socket.
Generates routes for the PgFlow Dashboard.
Authentication
In production, you should protect the dashboard with authentication.
Use the :on_mount option to add an authentication hook:
pgflow_dashboard "/pgflow",
repo: MyApp.Repo,
pubsub: MyApp.PubSub,
on_mount: [{MyAppWeb.Auth, :ensure_admin}]The :on_mount hooks are added to the LiveView session alongside
the dashboard's own mount hook. See Phoenix.LiveView.Router for
more information on on_mount hooks.
@spec session(Plug.Conn.t(), keyword(), String.t()) :: map()
Builds the LiveView session map used by PgFlowDashboard routes.
The session contains validated dashboard configuration and the resolved base path for links inside the dashboard.