DoubleEntryLedger.Migration (double_entry_ledger v0.3.0)

View Source

Migrations for the DoubleEntryLedger package.

Usage

Generate migration files with the install task:

mix double_entry_ledger.install

Or create a migration manually:

mix ecto.gen.migration setup_double_entry_ledger

Then edit the generated file:

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

  def up, do: DoubleEntryLedger.Migration.up()
  def down, do: DoubleEntryLedger.Migration.down()
end

Versioning

Each version represents an incremental schema change:

  • Version 1 — initial schema (v0.1.0)
  • Version 2 — FK constraint fixes, negative_limit replaces allowed_negative
  • Version 3 — trace_context JSONB column on commands for distributed tracing. The column is not indexed — consumers who need to query by trace context should add their own index.

New consumers use up() which applies all versions. Existing consumers upgrading from v0.1.0 use the :from option to skip already-applied versions:

# Upgrade from v0.1.0 (version 1 already applied via copied migrations)
def up, do: DoubleEntryLedger.Migration.up(from: 1)
def down, do: DoubleEntryLedger.Migration.down(version: 1)

Oban

This module does not manage Oban tables. The package does not ship an Oban migration to avoid locking consumers to a specific Oban version. Consumers manage Oban through their own application — see the README for setup instructions.

If upgrading from v0.1.0, your existing copied 2500_add_oban_jobs_table.exs continues to work — leave it in place.

Options

  • :version - Target migration version. Defaults to latest_version/0.
  • :from - Starting version (what's already applied). Defaults to 0 for up/1 and latest_version/0 for down/1.
  • :prefix - Schema prefix. Defaults to the configured :schema_prefix or "double_entry_ledger".

Summary

Functions

Rolls back migrations from :from down to :version.

Returns the latest migration version.

Runs migrations from :from up to :version.

Functions

down(opts \\ [])

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

Rolls back migrations from :from down to :version.

Options

  • :version - Target version to roll back to. Defaults to 0 (full rollback).
  • :from - Current version (what's applied). Defaults to latest_version/0.
  • :prefix - Schema prefix. Defaults to configured :schema_prefix.

latest_version()

@spec latest_version() :: pos_integer()

Returns the latest migration version.

up(opts \\ [])

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

Runs migrations from :from up to :version.

Options

  • :version - Target version. Defaults to latest_version/0.
  • :from - Starting version (already applied). Defaults to 0.
  • :prefix - Schema prefix. Defaults to configured :schema_prefix.