mix ash_scylla.gen (AshScylla v0.11.1)

Copy Markdown View Source

Generates a schema migration file from Ash DSL resource definitions.

Scans the project for Ash resources using AshScylla.DataLayer and produces a priv/migrations/<timestamp>_<name>.ex file containing structured %AshScylla.Schema{} entries organised by domain and resource.

Usage

# Auto-generate schema file with timestamp-based name
mix ash_scylla.gen --dev

# Generate with a specific schema module name
mix ash_scylla.gen AddUserTable

# Generate for a specific resource only
mix ash_scylla.gen --resource MyApp.User

Options

  • --dev — auto-name the schema file (timestamp-based). If no name argument is given, --dev is assumed.
  • --resource — only generate schema for the given resource module.
  • --force — force regeneration even if no schema changes detected.

Output

Generated files go to priv/migrations/ and use AshScylla.Schema with a struct-based format that groups resources by domain:

defmodule MyApp.Migrations.Schema20260615155440 do
  @moduledoc """
  Schema migration generated by `mix ash_scylla.gen`.
  """

  use AshScylla.Schema

  @impl AshScylla.Schema
  def change do
    [
      %AshScylla.Schema{
        domain: MyApp.Domain,
        resources: [
          %AshScylla.Schema.Resource{
            name: :users,
            statements: [
              "CREATE TABLE IF NOT EXISTS users (id UUID PRIMARY KEY, name TEXT, email TEXT)",
              "CREATE INDEX IF NOT EXISTS idx_users_email ON users (email)"
            ]
          }
        ]
      }
    ]
  end
end

Run migrations with: mix ash_scylla.migrate