Usher.Migration (Usher v0.5.1)

View Source

Migration helpers for creating and upgrading Usher tables.

Use this module in your application's migrations to create the necessary database tables for Usher.

Versioned Migrations

Starting with v0.2.0, Usher supports versioned migrations to allow incremental updates to the database schema. This is useful for existing installations that need to upgrade to new versions without losing data.

For new installations:

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

  def up do
    Usher.Migration.migrate_to_version(4)
  end

  def down do
    Usher.Migration.migrate_to_version(1)
  end
end

For existing installations upgrading:

defmodule MyApp.Repo.Migrations.UpgradeUsherInvitations do
  use Ecto.Migration
  import Usher.Migration

  def up do
    Usher.Migration.migrate_to_version(4)
  end

  def down do
    Usher.Migration.migrate_to_version(3)
  end
end

Summary

Functions

Returns the latest version of the Usher migrations.

Migrates the Usher tables to a specific version.

Returns a list of all valid migration versions.

Functions

latest_version()

@spec latest_version() :: non_neg_integer()

Returns the latest version of the Usher migrations.

migrate_to_version(to_version)

@spec migrate_to_version(non_neg_integer()) :: no_return()

Migrates the Usher tables to a specific version.

This function automatically detects the current migration version and applies only the necessary migrations to reach the latest version. It's safe to run multiple times.

Parameters

  • version: The target version to migrate to, e.g. 1, 2, 3, etc.

Examples

migrate_to_version(3)

valid_versions()

@spec valid_versions() :: [non_neg_integer()]

Returns a list of all valid migration versions.