# `MnemosynePostgres.Migrations`
[🔗](https://github.com/edlontech/mnemosyne_postgres/blob/main/lib/mnemosyne_postgres/migrations.ex#L1)

Migrations for the MnemosynePostgres tables and indexes.

## Usage

Create a migration in your application:

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

      def up, do: MnemosynePostgres.Migrations.up(version: 1, embedding_dimensions: 1536)
      def down, do: MnemosynePostgres.Migrations.down(version: 1)
    end

When a new version is released, generate a new migration:

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

      def up, do: MnemosynePostgres.Migrations.up(version: 2, embedding_dimensions: 1536)
      def down, do: MnemosynePostgres.Migrations.down(version: 2)
    end

## Options

  * `:version` - the target migration version (defaults to `1`)
  * `:embedding_dimensions` - (required for V1) the dimensionality of your embedding vectors
  * `:index_type` - `:hnsw` (default) or `:ivfflat`
  * `:hnsw_m` - max number of connections per layer for HNSW
  * `:hnsw_ef_construction` - size of the dynamic candidate list for HNSW
  * `:ivfflat_lists` - number of inverted lists for IVFFlat
  * `:prefix` - table name prefix, defaults to `"mnemosyne_"`

# `current_version`

```elixir
@spec current_version() :: pos_integer()
```

Returns the current migration version.

# `down`

```elixir
@spec down(keyword()) :: :ok
```

Runs the `down` migration for the given version.

Rolls back from the currently migrated version down to the target version.
When called with `version: 1`, it rolls back V1 (dropping all tables).

# `migrated_version`

```elixir
@spec migrated_version(Ecto.Repo.t(), String.t()) :: non_neg_integer()
```

Returns the version that has been migrated, based on the table comment.
Returns 0 if no migrations have run.

# `up`

```elixir
@spec up(keyword()) :: :ok
```

Runs the `up` migration for the given version.

Executes all migration versions from the currently migrated version
up to the target version sequentially.

---

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