action-requests-demo.jamey..../lib/action_requests_demo/release.ex
James Greenwood cc4cc65950
All checks were successful
build / build (push) Successful in 11s
Initial commit: Phoenix LiveView demo for interactive data tables with filtering, sorting, pagination, URL state, and progressive enhancement
Implements a fully-featured action requests table in a single LiveView module using Flop, Ecto, and SQLite. Includes:

- Fuzzy search, status/assignment filters, column sorting, 15-per-page pagination
- Real-time updates, bookmarkable URLs via `handle_params/3`
- JS-disabled fallback with GET forms (no duplicate logic)
- 1,000,000 seeded records, Tailwind + DaisyUI styling, light/dark themes
- Comprehensive README with comparisons to Django+React/Rails+React stacks
- 31 tests covering all scenarios

Tech: Phoenix 1.8+, LiveView, Flop, Ecto, SQLite, Elixir 1.15+
2025-11-17 14:42:00 +00:00

71 lines
1.8 KiB
Elixir

defmodule ActionRequestsDemo.Release do
@moduledoc """
Helpers for running tasks in a release environment.
This module is intended for commands invoked via:
bin/action_requests_demo eval "ActionRequestsDemo.Release.seed()"
"""
@app :action_requests_demo
@doc """
Run the database seeds script inside a release.
This is designed to be run against a *running* release (e.g. via
`bin/action_requests_demo eval ...` inside your Docker container),
so it does **not** try to start the application or endpoint again.
It only ensures Faker is running, then evaluates the standard
`priv/repo/seeds.exs` file, which uses `ActionRequestsDemo.Repo`.
"""
def seed do
ensure_app_started(ActionRequestsDemo.Repo)
ensure_app_started(:faker)
seeds_path = Application.app_dir(@app, "priv/repo/seeds.exs")
Code.require_file(seeds_path)
end
defp ensure_app_started(app_or_repo) do
case Application.ensure_all_started(app_or_repo) do
{:ok, _} ->
:ok
{:error, {:already_started, _pid}} ->
:ok
{:error, {:not_started, _}} ->
start_repo(app_or_repo)
{:error, reason} ->
raise "Could not start #{inspect(app_or_repo)}: #{inspect(reason)}"
end
rescue
UndefinedFunctionError ->
start_repo(app_or_repo)
end
defp start_repo(repo) when is_atom(repo) do
case repo.start_link() do
{:ok, _pid} ->
:ok
{:error, {:already_started, _pid}} ->
:ok
other ->
raise "Could not start #{inspect(repo)}: #{inspect(other)}"
end
end
defp start_repo(app) do
case Application.ensure_all_started(app) do
{:ok, _} -> :ok
{:error, {:already_started, _}} -> :ok
other -> raise "Could not start #{inspect(app)}: #{inspect(other)}"
end
end
end