AshClickhouse.Migration (AshClickhouse v0.3.0)

Copy Markdown View Source

Generates ClickHouse CREATE TABLE statements from Ash resources.

ClickHouse tables require an engine and an ORDER BY key. This module maps Ash primary keys and attributes to ClickHouse column definitions and produces a CREATE TABLE IF NOT EXISTS statement using the engine configured in the resource's clickhouse DSL block.

Summary

Functions

Generates ALTER TABLE ... ADD COLUMN IF NOT EXISTS statements for attributes that exist on the resource but not yet in the table. This is a minimal schema evolution pass: it adds new columns but does not drop or alter existing ones.

Generates the CREATE TABLE SQL for a resource.

Generates all migration statements (table creation) for a list of resources.

Functions

alter_table_cql(resource, repo)

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

Generates ALTER TABLE ... ADD COLUMN IF NOT EXISTS statements for attributes that exist on the resource but not yet in the table. This is a minimal schema evolution pass: it adds new columns but does not drop or alter existing ones.

Returns an empty list when the table does not exist yet (the CREATE TABLE statement handles initial creation) or when there are no new columns.

create_table_cql(resource)

@spec create_table_cql(module()) :: String.t()

Generates the CREATE TABLE SQL for a resource.

generate_resource_cql(resource)

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

Generates all migration statements (table creation) for a list of resources.