# `AshScylla.Release`
[🔗](https://github.com/ohhi-vn/ash_scylla/blob/main/lib/ash_scylla/release.ex#L15)

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"

## Migration Flow

`migrate/3` auto-discovers resources via `AshScylla.MixHelpers.find_all_resources/0`,
then calls `AshScylla.DataLayer.SchemaMigration.plan/2` and `migrate/2` for each.
Supports `:dry_run`, `:create_keyspace`, and `:resources` options.

## Rollback

CQL has no transactional DDL rollback. The `rollback/3` function logs a
warning — users must implement custom rollback logic (DROP TABLE, etc.).

# `create_keyspace`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@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])

---

*Consult [api-reference.md](api-reference.md) for complete listing*
