Behaviour for an ArcadeDB migration — a versioned pair of forward/backward steps.
Migrations are tenant-blind schema changes; author raw DDL/DML via Arcadic.command/4
in up/1 and down/1.
Only :ok finalizes a migration (Arcadic.Migrator marks it done); an
{:error, reason} return (or a raise) leaves the attempt's marker in place and the
next run follows the recovery contract in Arcadic.Migrator. Use the supplied
connection for synchronous database statements so Arcadic can verify the lease
before dispatch.
Implement schema_only?/0 only if both directions consist of schema operations
that can safely replay after a partial attempt. Implement preflight_down/1
to verify that a reversal is safe. Preflight callbacks only read and validate.
defmodule MyApp.Migrations.V1 do
@behaviour Arcadic.Migration
@impl true
def version, do: 1
@impl true
def up(conn) do
Arcadic.command!(conn, "CREATE VERTEX TYPE User IF NOT EXISTS", %{}, language: "sql")
:ok
end
@impl true
def down(conn) do
Arcadic.command!(conn, "DROP TYPE User IF EXISTS", %{}, language: "sql")
:ok
end
end
Summary
Callbacks
Reverse the migration. Only :ok finalizes; {:error, reason} leaves the attempt marker.
Check if reversal is safe. Read only and return value-free errors.
Whether either direction can safely replay after partially applied schema changes.
Apply the migration. Only :ok finalizes; {:error, reason} leaves the attempt marker.
A unique, ascending version (integer — typically a timestamp).
Callbacks
@callback down(Arcadic.Conn.t()) :: :ok | {:error, term()}
Reverse the migration. Only :ok finalizes; {:error, reason} leaves the attempt marker.
@callback preflight_down(Arcadic.Conn.t()) :: :ok | {:error, term()}
Check if reversal is safe. Read only and return value-free errors.
@callback schema_only?() :: boolean()
Whether either direction can safely replay after partially applied schema changes.
@callback up(Arcadic.Conn.t()) :: :ok | {:error, term()}
Apply the migration. Only :ok finalizes; {:error, reason} leaves the attempt marker.
@callback version() :: pos_integer()
A unique, ascending version (integer — typically a timestamp).