DurableObject.Migration (DurableObject v0.2.1)

Copy Markdown View Source

Versioned migrations for DurableObject tables.

Usage

Generate a migration:

mix ecto.gen.migration add_durable_objects

Then call the versioned migration functions:

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

  def up, do: DurableObject.Migration.up(version: 1)
  def down, do: DurableObject.Migration.down(version: 1)
end

Upgrading

When upgrading to a new version of DurableObject that requires schema changes, generate a new migration and specify both the base version (already applied) and the target version:

mix ecto.gen.migration upgrade_durable_objects_v3

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

  def up, do: DurableObject.Migration.up(base: 2, version: 3)
  def down, do: DurableObject.Migration.down(base: 2, version: 3)
end

This runs only version 3's changes, not versions 1-2 which are already applied.

Summary

Functions

Returns the current migration version.

Runs migrations down from the specified version.

Runs migrations up to the specified version.

Functions

current_version()

Returns the current migration version.

down(opts \\ [])

Runs migrations down from the specified version.

Options

  • :version - Version to roll back from (default: current version)
  • :base - Base version to roll back to (default: 0). Migrations will run from version down to base + 1.
  • :prefix - Table prefix for multi-tenancy (default: nil)

up(opts \\ [])

Runs migrations up to the specified version.

Options

  • :version - Target version (default: current version)
  • :base - Base version already applied (default: 0). Migrations will run from base + 1 to version.
  • :prefix - Table prefix for multi-tenancy (default: nil)