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

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 by `mix 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

## Flattening

`flatten/1` converts a mixed list of CQL strings and `%AshScylla.Schema{}`
structs into a flat list of CQL strings for execution.

# `cql`

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

# `resource`

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

# `t`

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

# `change`

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

# `flatten`

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

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

---

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