Writes a migration file into a repository, for the migration-generating
mix tasks of localize_sql.
A tagged decimal type is installed by running SQL — CREATE TYPE, the
aggregate functions — inside an Ecto migration. Rather than ship the
SQL as a file the consumer copies, these tasks generate a migration
whose up and down embed the SQL produced by a DDL module, so the
statements are baked into the consumer's own timestamped migration and
are not affected by a later upgrade of localize_sql.
This module renders and writes that migration. render/3 builds the
source and is independent of any repository; create_migration/5
writes it into a repository's migrations directory.
Summary
Functions
Writes a migration into a repository's migrations directory.
Renders a migration module as formatted Elixir source.
Returns a 14-digit UTC timestamp for a migration filename.
Functions
Writes a migration into a repository's migrations directory.
Arguments
repois anEcto.Repomodule.nameis the migration name in snake case, such as"add_cldr_unit". It is timestamped and camelized into the module name.up_sqlis the body of theup/0function.down_sqlis the body of thedown/0function.timestampis the 14-digit migration timestamp string, fromtimestamp/0.
Returns
- The path of the written file.
Renders a migration module as formatted Elixir source.
Arguments
moduleis the migration module name.up_sqlis the body of theup/0function — typically the output of aDDL.execute_each/1call.down_sqlis the body of thedown/0function.
Returns
- The migration source as a string.
Examples
iex> source = Localize.Ecto.Migration.Generator.render(
...> MyApp.Repo.Migrations.AddCldrUnit,
...> ~s|execute "CREATE TYPE public.cldr_unit AS (unit varchar, value numeric);"|,
...> ~s|execute "DROP TYPE public.cldr_unit;"|
...> )
iex> source =~ "def up do"
true
@spec timestamp() :: String.t()
Returns a 14-digit UTC timestamp for a migration filename.
Returns
- The timestamp as a string, such as
"20260731090501".