Generates CQL migration files from Ash resource definitions, and stores snapshots.
This task compares current Ash resource definitions against stored snapshots (and optionally the live database schema) to determine what DDL changes are needed, then generates a migration file with the appropriate CQL statements.
Usage
# Generate migrations for all resources
mix ash_scylla.generate_migrations
# Generate with a specific name
mix ash_scylla.generate_migrations add_user_table
# Dry run (print without creating files)
mix ash_scylla.generate_migrations --dry-run
# Check if migrations are needed (exit code 1 if so)
mix ash_scylla.generate_migrations --check
# Only update snapshots, don't generate migration files
mix ash_scylla.generate_migrations --snapshots-only
# Dev mode (auto-name with _dev suffix)
mix ash_scylla.generate_migrations --devOptions
--domains- comma-separated list of domain modules to generate for--snapshot-path- custom path for snapshots (default:priv/repo/resource_snapshots)--migration-path- custom path for migrations (default:priv/repo/migrations)--name- name for the migration file (auto-generated by default)--quiet- suppress file creation messages--no-format- don't format the generated Elixir code--dry-run- print migrations without creating files--check- return exit code 1 if migrations are needed--dev- create dev migrations (suffixed with_dev)--snapshots-only- only create snapshots, no migration files
Snapshots
Snapshots are JSON files stored in priv/<repo>/resource_snapshots/ that
capture the schema state of each resource at a point in time. The generator
compares the current resource definition against the most recent snapshot
to determine what changes need to be made.
Generated Migration Format
Generated migrations use AshScylla.Schema and contain CQL statements:
defmodule MyApp.Migrations.MigrateResources1 do
@moduledoc """
Migration for users.
This file was autogenerated with `mix ash_scylla.generate_migrations`
"""
use AshScylla.Schema
@impl AshScylla.Schema
def change do
[
"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