MnemosyneEcto.Migrations (mnemosyne_ecto v0.2.0)

Copy Markdown View Source

Database-agnostic migrations for MnemosyneEcto tables and indexes.

Write one migration in your application. MnemosyneEcto.Adapter emits the correct DDL for PostgreSQL with pgvector or SQLite with sqlite-vec. V1 creates all three dynamically prefixed tables: graph nodes, node metadata, and permanent ingestion records.

Usage

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

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

Clean-break reset

V1 was rewritten for durable ingestion records. Existing MnemosyneEcto tables or databases from pre-ingestion versions must be dropped and recreated. The current version remains 1; there is no V2 upgrade, data conversion, session compatibility, or dual read/write path.

Options

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

SQLite uses a brute-force vec_distance_cosine scan, so PostgreSQL-only index options are ignored for SQLite repos.

Summary

Functions

Returns the current migration version.

Runs the down migration for the given version.

Returns the version that has been migrated for the given prefix.

Runs the up migration for the given version.

Functions

current_version()

@spec current_version() :: pos_integer()

Returns the current migration version.

down(opts \\ [])

@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(repo, prefix \\ "mnemosyne_")

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

Returns the version that has been migrated for the given prefix.

Returns 0 if no migrations have run.

up(opts \\ [])

@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.