# `ExDataSketch.Storage.Ecto.Migration`
[🔗](https://github.com/thanos/ex_data_sketch/blob/main/lib/ex_data_sketch/storage/ecto/migration.ex#L1)

Migration helper for creating the `ex_data_sketch_sketches` table.

Use `mix ex_data_sketch.gen.migration` to generate a migration file
that calls `up_commands/0` and `down_commands/0` from this module.

## Table Structure

The migration creates a table named `ex_data_sketch_sketches` with:

- `id` -- auto-incrementing primary key
- `key` -- unique string key for the sketch (with unique index)
- `sketch_type` -- the sketch family name (e.g., "hll", "cms")
- `data` -- binary column storing the EXSK v2 frame
- `inserted_at` -- timestamp
- `updated_at` -- timestamp

## Usage in Migrations

    defmodule MyApp.Repo.Migrations.AddExDataSketchSketches do
      use Ecto.Migration

      def up do
        Enum.each(ExDataSketch.Storage.Ecto.Migration.up_commands(), &execute/1)
      end

      def down do
        Enum.each(ExDataSketch.Storage.Ecto.Migration.down_commands(), &execute/1)
      end
    end

# `down_commands`

```elixir
@spec down_commands() :: [String.t()]
```

Returns the list of SQL commands to drop the sketches table.

Each command is a SQL string suitable for passing to `Ecto.Migration.execute/1`.

# `table_name`

```elixir
@spec table_name() :: String.t()
```

Returns the table name used by the migration.

## Examples

    iex> ExDataSketch.Storage.Ecto.Migration.table_name()
    "ex_data_sketch_sketches"

# `up_commands`

```elixir
@spec up_commands() :: [String.t()]
```

Returns the list of SQL commands to create the sketches table and index.

Each command is a SQL string suitable for passing to `Ecto.Migration.execute/1`.

---

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