feat: more UI cleanup

This commit is contained in:
2026-04-24 18:22:25 +02:00
parent e51566d707
commit 6824b89691
11 changed files with 696 additions and 3 deletions

43
lib/bds/repo_bootstrap.ex Normal file
View File

@@ -0,0 +1,43 @@
defmodule BDS.RepoBootstrap do
@moduledoc false
use GenServer
def start_link(opts \\ []) do
GenServer.start_link(__MODULE__, opts, name: __MODULE__)
end
def init(opts) do
:ok = ensure_ready(opts)
{:ok, %{}}
end
def ensure_ready(opts \\ []) do
repo = Keyword.get(opts, :repo, BDS.Repo)
if Keyword.get(opts, :migrate?, true) do
:ok = ensure_schema(Keyword.put(opts, :repo, repo))
end
if repo == BDS.Repo do
case BDS.Projects.ensure_default_project() do
{:ok, _project} -> :ok
{:error, reason} -> raise "failed to ensure default project: #{inspect(reason)}"
end
else
:ok
end
end
def ensure_schema(opts \\ []) do
repo = Keyword.get(opts, :repo, BDS.Repo)
migrations_path = Keyword.get(opts, :migrations_path, migrations_path())
_versions = Ecto.Migrator.run(repo, migrations_path, :up, all: true)
:ok
end
def migrations_path do
Path.expand("../../priv/repo/migrations", __DIR__)
end
end