DoubleEntryLedger.Migration (double_entry_ledger v0.3.0)
View SourceMigrations for the DoubleEntryLedger package.
Usage
Generate migration files with the install task:
mix double_entry_ledger.installOr create a migration manually:
mix ecto.gen.migration setup_double_entry_ledgerThen 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()
endVersioning
Each version represents an incremental schema change:
- Version 1 — initial schema (v0.1.0)
- Version 2 — FK constraint fixes,
negative_limitreplacesallowed_negative - Version 3 —
trace_contextJSONB 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 tolatest_version/0.:from- Starting version (what's already applied). Defaults to0forup/1andlatest_version/0fordown/1.:prefix- Schema prefix. Defaults to the configured:schema_prefixor"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
@spec down(keyword()) :: :ok
Rolls back migrations from :from down to :version.
Options
:version- Target version to roll back to. Defaults to0(full rollback).:from- Current version (what's applied). Defaults tolatest_version/0.:prefix- Schema prefix. Defaults to configured:schema_prefix.
@spec latest_version() :: pos_integer()
Returns the latest migration version.
@spec up(keyword()) :: :ok
Runs migrations from :from up to :version.
Options
:version- Target version. Defaults tolatest_version/0.:from- Starting version (already applied). Defaults to0.:prefix- Schema prefix. Defaults to configured:schema_prefix.