AshScylla.DataLayer.Codegen (AshScylla v1.4.0)

Copy Markdown View Source

Codegen tooling for mix ash.codegen / mix ash_scylla.gen.

This module is intentionally separate from AshScylla.DataLayer, which implements the runtime Ash.DataLayer behaviour. None of the functions here are part of the runtime data-layer contract — they render CQL CREATE TABLE / CREATE INDEX statements, render migration files, and persist schema-hash metadata used for change detection between codegen runs.

Summary

Functions

Computes the meta map for a list of resources.

Filters a list of resources to only those whose schema has changed compared to the previous meta map.

Loads the codegen meta file from disk.

Merges previous meta with updated entries for changed resources.

Saves the codegen meta map to disk.

Functions

codegen(action, opts)

@spec codegen(
  atom(),
  keyword()
) :: {:ok, term()} | {:error, term()}

compute_codegen_meta(resources)

@spec compute_codegen_meta([module()]) :: %{required(String.t()) => integer()}

Computes the meta map for a list of resources.

Returns a map of resource_key => schema_hash that can be used to detect changes between runs.

filter_changed_resources(resources, previous_meta)

@spec filter_changed_resources([module()], map()) :: [module()]

Filters a list of resources to only those whose schema has changed compared to the previous meta map.

Returns the list of changed resources.

generate_migration_name(resource, action, opts)

@spec generate_migration_name(module(), atom(), keyword()) :: String.t()

generate_resource_cql(resource)

@spec generate_resource_cql(module()) :: [String.t()]

load_codegen_meta(meta_file)

@spec load_codegen_meta(String.t()) :: map()

Loads the codegen meta file from disk.

Returns an empty map if the file doesn't exist or can't be parsed.

merge_codegen_meta(previous_meta, changed_resources, current_meta)

@spec merge_codegen_meta(map(), [module()], map()) :: map()

Merges previous meta with updated entries for changed resources.

render_migration_file(resource, statements, repo)

@spec render_migration_file(module(), [String.t()], module()) :: String.t()

save_codegen_meta(meta_file, meta)

@spec save_codegen_meta(String.t(), map()) :: :ok

Saves the codegen meta map to disk.