# `mix ancestry_ex.gen.migration`
[🔗](https://github.com/rocket4ce/ancestry_ex/blob/v0.1.0/lib/mix/tasks/ancestry_ex.gen.migration.ex#L1)

Generates a migration that adds the ancestry column (and optional cache
columns) to an existing table.

    $ mix ancestry_ex.gen.migration categories
    $ mix ancestry_ex.gen.migration categories --cache-depth --counter-cache
    $ mix ancestry_ex.gen.migration categories --from-parent-id

The ancestry column is created with the `"C"` collation and a btree index,
so prefix searches (`LIKE '/1/2/%'`) use the index.

## Options

  * `--format` - `materialized_path2` (default) or `materialized_path`.
  * `--column` - name of the ancestry column, `ancestry` by default.
  * `--cache-depth` - adds an `ancestry_depth` integer column.
  * `--virtual-depth` - adds `ancestry_depth` as a PostgreSQL generated column.
  * `--counter-cache` - adds a `children_count` integer column.
  * `--from-parent-id` - fills the new columns from an existing adjacency
    list column with a recursive query, so an existing tree is migrated in
    place.
  * `--parent-column` - the adjacency list column, `parent_id` by default.
  * `--repo` - the repo, defaults to `MyApp.Repo`.
  * `--migrations-path` - where to write the migration, defaults to the
    repo's `priv/repo/migrations`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
