Anvil.Schema.Migration behaviour (Anvil v0.1.1)
View SourceForward-only migrations between schema versions.
Provides utilities for migrating labels from one schema version to another using transform callbacks.
Summary
Callbacks
Transform callback behaviour for schema migrations.
Functions
Freezes a schema version when the first label is submitted.
Migrates labels from one schema version to another.
Validates that a label payload conforms to a schema version.
Callbacks
Functions
@spec freeze_schema_version(binary()) :: {:ok, Anvil.Schema.SchemaVersion.t()} | {:error, term()}
Freezes a schema version when the first label is submitted.
This is typically called automatically via a database trigger or application hook.
@spec migrate_labels( [Anvil.Schema.Label.t()], non_neg_integer(), non_neg_integer(), module(), keyword() ) :: {:ok, map()} | {:error, term()}
Migrates labels from one schema version to another.
Options
:batch_size- Number of labels to process per batch (default: 100):dry_run- If true, only validates transformations without creating new labels:transformer- Module implementing transform/3 callback
Examples
iex> migrate_labels(labels, 1, 2, MyApp.Transforms.V1ToV2)
{:ok, %{migrated: 150, failed: 0}}
iex> migrate_labels(labels, 1, 2, MyApp.Transforms.V1ToV2, dry_run: true)
{:ok, %{valid: 150, invalid: 0}}
@spec validate_against_schema(map(), Anvil.Schema.SchemaVersion.t()) :: {:ok, map()} | {:error, [term()]}
Validates that a label payload conforms to a schema version.
Returns {:ok, payload} if valid, {:error, errors} if invalid.