PhoenixMountable.Migrations.Generator (PhoenixMountable v0.2.1)

Copy Markdown View Source

Writes the host's migration for installing or upgrading a library.

Used by mix phoenix_mountable.gen.migration and by PhoenixMountable.Igniter. The version the host is at is read from its existing migrations: the highest MyLib.Migrations.up(version: n) among them. That works before the database is migrated (a new developer, CI), and keeps the host's history reproducible.

Summary

Functions

The highest version pinned by up(version: n) calls to migrations in the .exs files of dir.

The name and module body of the migration taking migrations from version from to to in repo.

Writes the migration with mix ecto.gen.migration, then fills in its body.

Functions

pinned_version(migrations, dir)

@spec pinned_version(module(), Path.t()) ::
  {:ok, non_neg_integer()} | {:unpinned, [Path.t()]}

The highest version pinned by up(version: n) calls to migrations in the .exs files of dir.

Returns {:ok, version} (0 when none), or {:unpinned, files} when a file calls up/0 or up/1 without a version, which cannot be read without the database.

render(migrations, repo, from, to)

@spec render(
  module(),
  module() | {module(), atom()},
  non_neg_integer(),
  non_neg_integer()
) ::
  {String.t(), String.t()}

The name and module body of the migration taking migrations from version from to to in repo.

The body is what goes inside the migration module after use Ecto.Migration. The file itself is written by Ecto's mix ecto.gen.migration (see write!/5) or by Igniter's Igniter.Libs.Ecto.gen_migration/4, so its path, timestamp, module name and use line follow the host's Ecto conventions.

write!(migrations, repo, from, to, args \\ [])

@spec write!(module(), module(), non_neg_integer(), non_neg_integer(), [String.t()]) ::
  Path.t()

Writes the migration with mix ecto.gen.migration, then fills in its body.

args are passed to Ecto's task: -r/--repo and --migrations-path. Returns the file written.