Runs generated ClickHouse migration files for a repo.
Migrations are version-tracked in a schema_migrations table so each file is
applied at most once. The same versioned pipeline backs both
mix ash_clickhouse.migrate (run/2, output via Mix.shell()) and
AshClickhouse.Release.migrate/3 (which passes logger: true so output goes
through Logger instead — Mix is unavailable inside a release).
Migration modules implement AshClickhouse.Schema. The version comes from
version/0 when exported, falling back to the leading timestamp in the
filename (e.g. 20240101120000_add_users.exs) so files generated before
version/0 support still work.
Summary
Functions
Returns the versions already applied for a repo, sorted.
Removes a migration version from the tracking table (rollback).
Loads and sorts the migration files under a path.
Creates the version-tracking table for a repo if it doesn't exist.
Runs pending migrations for a repo and returns a summary.
Records a migration version as applied.
Rolls back applied migrations for a repo down to (but not including) a target version.
Runs pending migrations for a repo, Mix-style.
DDL used to create the version-tracking table.
The name of the version-tracking table.
Functions
Returns the versions already applied for a repo, sorted.
Removes a migration version from the tracking table (rollback).
Loads and sorts the migration files under a path.
Returns [%{version: String.t(), module: module()}] sorted by version,
including only files that define at least one module. Modules whose version
cannot be determined still appear (their version is the full filename).
Creates the version-tracking table for a repo if it doesn't exist.
Runs pending migrations for a repo and returns a summary.
Creates the schema_migrations table if needed, skips versions already
applied, executes change/0 for the rest, and records each applied version.
Options
:migration_path— directory containing*.exsmigrations (default"priv/repo/migrations"):dry_run— log statements without executing or recording:logger— emit output viaLoggerinstead ofMix.shell()(forAshClickhouse.Release)
Returns {:ok, %{applied: [module()], skipped: [module()]}} or
{:error, term()} — a {module(), term()} tuple when a specific migration
failed, or a bare term() when the tracking table could not be created.
Records a migration version as applied.
@spec rollback(module(), String.t() | non_neg_integer() | :all | nil, keyword()) :: {:ok, map()} | {:error, term()}
Rolls back applied migrations for a repo down to (but not including) a target version.
Each rolled-back migration executes down/0 when exported, falling back to
AshClickhouse.Migration.reverse_statement/1 over change/0 for files that
predate down/0 support. Statements that cannot be reversed are skipped with
a warning. :all (or nil/0) rolls back every applied migration.
Returns {:ok, %{rolled_back: [module()], skipped: [module()]}} or
{:error, term()} — a {module(), term()} tuple when a specific migration
failed, or a bare term() when the tracking table could not be created.
Runs pending migrations for a repo, Mix-style.
Equivalent to migrate/2 but prints through Mix.shell() and raises on
failure, matching the behaviour of mix ash_clickhouse.migrate.
@spec schema_migrations_create_sql() :: String.t()
DDL used to create the version-tracking table.
@spec schema_migrations_table() :: String.t()
The name of the version-tracking table.