Durable.Migration.Base behaviour (Durable v0.1.0-rc)

View Source

Base module for Durable internal migrations.

This module provides the behaviour and DSL for creating Durable migrations. Each migration is a module that implements version/0, up/1, and down/1.

Usage

defmodule Durable.Migration.Migrations.V20260103120000AddCompensation do
  use Durable.Migration.Base

  @impl true
  def version, do: 20_260_103_120_000

  @impl true
  def up(prefix) do
    alter table(:workflow_executions, prefix: prefix) do
      add(:compensation_data, :jsonb)
    end
  end

  @impl true
  def down(prefix) do
    alter table(:workflow_executions, prefix: prefix) do
      remove(:compensation_data)
    end
  end
end

The prefix argument is the PostgreSQL schema name (default: "durable"). All Ecto.Migration functions are available (create, alter, drop, execute, etc.).

Summary

Callbacks

Runs the migration down (rollback changes).

Runs the migration up (apply changes).

Returns the migration version as a positive integer.

Callbacks

down(prefix)

@callback down(prefix :: String.t()) :: :ok

Runs the migration down (rollback changes).

The prefix argument is the PostgreSQL schema name.

up(prefix)

@callback up(prefix :: String.t()) :: :ok

Runs the migration up (apply changes).

The prefix argument is the PostgreSQL schema name.

version()

@callback version() :: pos_integer()

Returns the migration version as a positive integer.

Version format: YYYYMMDDHHmmss (14 digits) Example: 20260103120000