Chimeway.Install.Migrations (chimeway v1.1.0)

Copy Markdown View Source

Copy-based installer core for Chimeway schema migrations.

Reads canonical templates from priv/chimeway_migrations/ and writes host-namespaced files under priv/repo/migrations/ with slug-based idempotency.

Oban job tables are not included — configure Oban separately via Oban integration guide.

Summary

Functions

Extracts the stable migration slug from a template filename or marker comment.

Finds an existing host migration file matching *_{slug}.exs, or nil.

Derives the host migrations module prefix string from a repo module.

Returns [{order, slug, template_path}] sorted by order prefix.

Renders one migration template for a host migration namespace and generation mode.

Resolves the host Ecto repo module.

Resolves the host Ecto repo module or raises RepoMissingError.

Rewrites template namespace from Chimeway.Repo.Migrations to the host prefix.

Generates host migration files from shipped templates.

Functions

extract_slug(filename)

Extracts the stable migration slug from a template filename or marker comment.

find_existing_by_slug(slug, migrations_dir \\ "priv/repo/migrations")

Finds an existing host migration file matching *_{slug}.exs, or nil.

host_migrations_prefix(repo)

Derives the host migrations module prefix string from a repo module.

iex> Chimeway.Install.Migrations.host_migrations_prefix(MyApp.Repo)
"MyApp.Repo.Migrations"

list_templates()

Returns [{order, slug, template_path}] sorted by order prefix.

render_template(content, host_prefix, generation_prefix)

Renders one migration template for a host migration namespace and generation mode.

This composes host namespace rewriting with the explicit Chimeway prefix sentinel. It deliberately does not rewrite relation names; template helper conversion owns that prefixing behavior.

resolve_repo(repo_override \\ nil)

Resolves the host Ecto repo module.

Returns {:ok, repo}, {:error, :repo_missing}, or {:error, :umbrella_root}.

resolve_repo!()

Resolves the host Ecto repo module or raises RepoMissingError.

rewrite_namespace(content, host_prefix)

Rewrites template namespace from Chimeway.Repo.Migrations to the host prefix.

run(opts \\ [])

Generates host migration files from shipped templates.

Options:

  • :repo — override host repo module (defaults to resolved config or mix.exs inference)
  • :io — IO device for progress output (defaults to Mix.shell())
  • :prefix — generation mode, either :chimeway or :public (defaults to :chimeway)

Returns :ok on success, {:error, :repo_missing} when the host repo cannot be resolved, or {:error, :umbrella_root} when run from an umbrella root without explicit repo config.