1. MooseStack
  2. Moose Migrate
  3. Migration Plan Format

On this page

Plan StructureOperation ReferenceTable OperationsColumn OperationsSQL OperationsColumn DefinitionData TypesScalar TypesComplex TypesSee Also

Migration Plan Format

The migrations/plan.yaml file is the declarative source of truth for pending database changes in Moose. It defines the exact sequence of operations Moose will execute to transition your production database to the desired state.

This reference documents the file structure, supported operations, and data type definitions found in generated plans.

Plan Structure

A migration plan is a YAML document with the following root properties:

FieldTypeDescription
created_atString (ISO 8601)Timestamp when the plan was generated. Used for versioning and audit trails.
operationsArrayOrdered list of migration operations to execute.
migrations/plan.yaml
created_at: 2025-01-14T10:30:00Zoperations:  - DropTableColumn: ...  - AddTableColumn: ...

Operation Reference

Operations are the atomic units of change in a migration plan. Moose executes them sequentially.

Table Operations

CreateTable

Creates a new ClickHouse table.

migrations/plan.yaml
- CreateTable:    table:      name: <string>      columns: [<ColumnDefinition>]      order_by: [<string>]      engine: <EngineType>
FieldDescription
nameName of the table to create.
columnsList of column definitions.
order_byArray of column names used for the sorting key.
engineClickHouse table engine (e.g., MergeTree, ReplacingMergeTree).

DropTable

Permanently removes a table and all its data.

migrations/plan.yaml
- DropTable:    table: <string>
FieldDescription
tableName of the table to drop.

Column Operations

AddTableColumn

Adds a new column to an existing table.

migrations/plan.yaml
- AddTableColumn:    table: <string>    column: <ColumnDefinition>
FieldDescription
tableTarget table name.
columnFull definition of the new column.

DropTableColumn

Removes a column from a table. Destructive operation.

migrations/plan.yaml
- DropTableColumn:    table: <string>    column_name: <string>
FieldDescription
tableTarget table name.
column_nameName of the column to remove.

RenameTableColumn

Renames a column while preserving its data.

migrations/plan.yaml
- RenameTableColumn:    table: <string>    before_column_name: <string>    after_column_name: <string>
FieldDescription
tableTarget table name.
before_column_nameCurrent name of the column.
after_column_nameNew name for the column.

ModifyTableColumn

Changes a column's data type or properties.

migrations/plan.yaml
- ModifyTableColumn:    table: <string>    before_column: <ColumnDefinition>    after_column: <ColumnDefinition>
FieldDescription
tableTarget table name.
before_columnSnapshot of the column state before modification.
after_columnDesired state of the column.

SQL Operations

RawSql

Executes arbitrary SQL statements. Used for custom migrations, backfills, or unsupported operations.

migrations/plan.yaml
- RawSql:    sql: [<string>]    description: <string>
FieldDescription
sqlList of SQL statements to execute in order.
descriptionHuman-readable explanation of the operation's purpose.

Column Definition

Every column in a CreateTable, AddTableColumn, or ModifyTableColumn operation follows this structure:

migrations/plan.yaml
name: <string>data_type: <DataType>required: <boolean>unique: <boolean>primary_key: <boolean>default: <string> | nullcomment: <string> | nullannotations: [[<string>, <boolean>]]
PropertyTypeDescription
nameStringColumn identifier.
data_typeTypeClickHouse data type (see below).
requiredBooleanIf true, the column is NOT NULL.
uniqueBoolean(Metadata) Whether the field is marked unique in the model.
primary_keyBooleanWhether the field is part of the primary key.
defaultStringDefault value expression (e.g., 'active', 0, now()).

Data Types

Moose maps data model types to ClickHouse types in the plan.

Scalar Types

TypeYAML Representation
StringString
BooleanBoolean
IntegerInt8, Int16, Int32, Int64, UInt8...
FloatFloat32, Float64
DateDate, Date32, DateTime
UUIDUUID

Complex Types

Nullable

Wraps another type to allow NULL values.

migrations/plan.yaml
data_type:  Nullable:    nullable: String

Arrays

List of values of a single type.

migrations/plan.yaml
data_type:  Array:    elementType: String    elementNullable: false

Enums

Fixed set of string or integer values.

migrations/plan.yaml
data_type:  Enum:    name: "Status"    values:      - name: "ACTIVE"        value: { String: "active" }      - name: "INACTIVE"        value: { String: "inactive" }

Nested (Structs)

Hierarchical data structures.

migrations/plan.yaml
data_type:  Nested:    name: "Address"    columns: [<ColumnDefinition>]    jwt: false

LowCardinality

Storage optimization for columns with few unique values.

migrations/plan.yaml
data_type:  LowCardinality:    nullable: String

See Also

  • Migration Modes — Overview of the two schema evolution modes in Moose
  • Planned Migrations — Reference documentation for the Planned Migrations system in Moose
  • Lifecycle Management — Reference documentation for the Lifecycle Management system in Moose
  • ClickHouse Data Types — ClickHouse official documentation
  • Overview
  • Quick Start
  • Templates / Examples
Fundamentals
  • Moose Runtime
  • MooseDev MCP
  • Data Modeling
MooseStack in your App
  • App / API frameworks
Modules
  • Moose OLAP
  • Moose Streaming
  • Moose Workflows
  • Moose APIs
Deployment & Lifecycle
  • Moose Migrate
    • Migration Modes
    • Automatic Migrations
    • Planned Migrations
    • Plan Reference
    • Executing Migrations
    • moose migrate (CLI)
    • moose prod (Runtime)
    • Lifecycle Management
    • Fully Managed
    • Deletion Protected
    • Externally Managed
    • Advanced Topics
    • Failed Migrations
  • Moose Deploy
Reference
  • API Reference
  • Data Types
  • Table Engines
  • CLI
  • Configuration
  • Observability Metrics
  • Help
  • Changelog
Contribution
  • Documentation
  • Framework
FiveonefourFiveonefour
Fiveonefour Docs
MooseStackTemplates
Changelog
Source506