AshScylla.Schema behaviour (AshScylla v0.11.1)

Copy Markdown View Source

Behaviour for schema migration modules loaded from priv/migrations.

Schema files are optional Elixir modules that return CQL statements from change/0. They can return raw CQL strings or structured %AshScylla.Schema{} entries organised by domain and resource. ## Struct-based schema (generated bymix ash_scylla.gen`) defmodule MyApp.Migrations.Schema20260615155440 do use 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)", "CREATE INDEX IF NOT EXISTS idx_users_email ON users (email)" ] } ] } ] end end ## Flat CQL list (hand-written) defmodule MyApp.Migrations.AddUserTable do use AshScylla.Schema def change do [ "CREATE TABLE IF NOT EXISTS users (id UUID PRIMARY KEY, name TEXT)" ] end end

Summary

Functions

Flattens a change/0 result (mix of CQL strings and Schema structs) into a flat list of CQL strings.

Types

cql()

@type cql() :: String.t()

resource()

@type resource() :: %AshScylla.Schema.Resource{name: atom(), statements: [cql()]}

t()

@type t() :: %AshScylla.Schema{domain: module(), resources: [resource()]}

Callbacks

change()

@callback change() :: [cql() | t()]

Functions

flatten(change_result)

@spec flatten([cql() | t()]) :: [cql()]

Flattens a change/0 result (mix of CQL strings and Schema structs) into a flat list of CQL strings.