AshScylla.Release (AshScylla v0.10.3)

Copy Markdown View Source

Release task helpers for running AshScylla migrations in production without Mix installed.

Usage

Add a module like this to your project:

defmodule MyApp.Release do
  @app :my_app

  def migrate do
    load_app()

    for repo <- repos() do
      AshScylla.Release.migrate(repo, repos())
    end
  end

  def rollback(repo, version) do
    load_app()
    AshScylla.Release.rollback(repo, version, repos())
  end

  defp repos do
    Application.fetch_env!(@app, :ash_scylla_repos)
  end

  defp load_app do
    Application.load(@app)
  end
end

Then in your release:

bin/my_app eval "MyApp.Release.migrate"

Configuration

In your config:

config :my_app, :ash_scylla_repos, [MyApp.Repo]

Or configure per-repo:

config :my_app, MyApp.Repo,
  nodes: ["127.0.0.1:9042"],
  keyspace: "my_app_prod"

Summary

Functions

Creates the keyspace for a repo if it doesn't exist.

Returns all AshScylla resources for the given repos.

Runs migrations for all configured repos.

Rolls back a migration to a specific version.

Functions

create_keyspace(repo, opts \\ [])

@spec create_keyspace(
  module(),
  keyword()
) :: :ok | {:error, term()}

Creates the keyspace for a repo if it doesn't exist.

Examples

AshScylla.Release.create_keyspace(MyApp.Repo)

find_resources(all_repos, opts)

@spec find_resources(
  [module()],
  keyword()
) :: [module()]

Returns all AshScylla resources for the given repos.

Scans the application's modules for resources that use AshScylla.DataLayer.

migrate(repo, all_repos, opts \\ [])

@spec migrate(module(), [module()], keyword()) :: :ok | {:error, term()}

Runs migrations for all configured repos.

Options

  • :resources - List of specific resource modules to migrate (default: all)
  • :dry_run - If true, only log statements without executing
  • :create_keyspace - Create the keyspace before migrating

Examples

AshScylla.Release.migrate(MyApp.Repo, [MyApp.Repo])

AshScylla.Release.migrate(MyApp.Repo, [MyApp.Repo], resources: [MyApp.User])

AshScylla.Release.migrate(MyApp.Repo, [MyApp.Repo], dry_run: true)

rollback(repo, version, all_repos)

@spec rollback(module(), non_neg_integer() | String.t(), [module()]) ::
  :ok | {:error, term()}

Rolls back a migration to a specific version.

Since CQL has no transactional DDL, rollback must be handled manually. This function provides a framework for rollbacks — users should define their own rollback logic based on their migration history.

Examples

AshScylla.Release.rollback(MyApp.Repo, 20240101000000, [MyApp.Repo])