AshScylla.Migration (AshScylla v0.1.1)

Copy Markdown View Source

Helpers for working with ScyllaDB migrations using Exandra.

This module provides utilities to help generate CQL statements for ScyllaDB tables based on Ash resource definitions.

Note: For actual migrations, use Exandra with Ecto.Migration directly. See the Exandra documentation for more details on writing migrations.

Example Migration

defmodule MyApp.Repo.Migrations.CreateUsers do
  use Ecto.Migration

  def change do
    execute "CREATE TABLE users (id UUID PRIMARY KEY, name TEXT, email TEXT)"
  end
end

Summary

Functions

Generates CQL CREATE INDEX statements for secondary indexes.

Generates a CQL CREATE TABLE statement for an Ash resource.

Define a User Defined Type (UDT) in ScyllaDB.

Generates a CQL DROP INDEX statement for a secondary index.

Drop a User Defined Type (UDt) in ScyllaDB.

Returns the keyspace for a resource if configured via DSL. Note: This is a placeholder for future DSL implementation.

Functions

create_secondary_indexes_cql(resource)

Generates CQL CREATE INDEX statements for secondary indexes.

Returns a list of CQL strings that should be executed in migrations.

Example

defmodule MyApp.Repo.Migrations.CreateUserIndexes do
  use Ecto.Migration

  def change do
    AshScylla.Migration.create_secondary_indexes_cql(MyApp.User)
    |> Enum.each(&execute/1)
  end
end

create_table_cql(resource)

Generates a CQL CREATE TABLE statement for an Ash resource.

Note: This is a helper that returns a CQL string. You need to execute this in an Ecto migration using execute/1.

create_type(type_name, list)

Define a User Defined Type (UDT) in ScyllaDB.

Example

create_type "full_name" do
  field :first_name, :text
  field :last_name, :text
end

This generates:

CREATE TYPE full_name (first_name TEXT, last_name TEXT)

drop_secondary_index_cql(resource, index_name)

Generates a CQL DROP INDEX statement for a secondary index.

drop_type(type_name)

Drop a User Defined Type (UDt) in ScyllaDB.

keyspace(resource)

Returns the keyspace for a resource if configured via DSL. Note: This is a placeholder for future DSL implementation.