FiveonefourFiveonefour
Fiveonefour Docs
MooseStackTemplatesGuides
Release Notes
Source514
  1. MooseStack
  2. Moose Migrate
  3. Automatic Migrations

On this page

CommandProduction UsageBehaviorOperation ReferenceLimitations and SafetyRenaming FieldsDestructive OperationsConfigurationCLI Output ReferenceExample OutputSee Also

Automatic Migrations

Automatic migrations are a schema evolution mechanism in Moose that automatically detects changes in your data models and applies them to the underlying database in real-time. This system is designed primarily for local development.

Command

Automatic migrations are enabled implicitly when running the development server:

moose dev

Production Usage

While technically possible to use automatic migrations in production environments, it is strongly discouraged.

Data Loss Risk

Automatic migrations will immediately drop columns containing data if a field is renamed or removed in the code. In production, this leads to irreversible data loss.

Production deployments should always use Planned Migrations to ensure schema changes are reviewed, tested, and safe.

Behavior

When active, the auto-inference engine performs the following cycle:

  1. Monitor: Watches the file system for changes in exported table definitions in your data model files.
  2. Diff: Compares the code-defined schema against the actual schema of the running ClickHouse instance.
  3. Generate: Creates the necessary SQL DDL statements to reconcile the difference.
  4. Apply: Executes the SQL statements immediately against the database.

Operation Reference

The following table describes how code changes are translated into database operations by the auto-inference engine.

Code ChangeDatabase OperationSQL Equivalent (Approximate)Data Impact
New TableCreate TableCREATE TABLE ...Safe
Add FieldAdd ColumnALTER TABLE ... ADD COLUMN ...Safe
Remove FieldDrop ColumnALTER TABLE ... DROP COLUMN ...Destructive (Data Loss)
Change Field TypeModify ColumnALTER TABLE ... MODIFY COLUMN ...Potentially Destructive (Cast dependent)
Rename FieldDrop + AddDROP COLUMN old; ADD COLUMN newDestructive (Data Loss - see limitations)
Remove TableDrop TableDROP TABLE ...Destructive

Limitations and Safety

Renaming Fields

The auto-inference engine is stateless regarding user intent. It cannot distinguish between renaming a field and deleting one field to add another.

If you rename user_id to uid:

  1. Moose sees user_id is missing from the code -> Generates DROP COLUMN user_id.
  2. Moose sees uid is new in the code -> Generates ADD COLUMN uid.

Result: The column is dropped and re-added empty. Data in the original column is lost immediately.

Renaming in Production

To rename columns without data loss, you must use Planned Migrations and manually adjust the migration plan to use a rename operation instead of drop + add.

Destructive Operations

Automatic migrations do not prompt for confirmation before dropping tables or columns. If you comment out a table export or remove a field definition, the corresponding data structure in the database is removed immediately.

Configuration

Automatic migrations rely on the olap feature flag in your project configuration.

moose.config.toml
[features]olap = true # enabled by default

CLI Output Reference

The CLI communicates migration actions via standard output prefixes in the terminal.

SymbolMeaningDescription
+AddCreating a new table or adding a column.
-RemoveDropping a table or removing a column.
~ModifyChanging a column's data type or properties.

Example Output

⢹ Processing Infrastructure changes from file watcher             ~ Table page_views:                  Column changes:                    + user_agent: String                    - referrer: String                    ~ timestamp: DateTime -> DateTime64(3)

See Also

  • Planned Migrations - The reference for production-grade migration workflows.
  • Schema Change Reference - Detailed breakdown of migration plan objects.
  • Serverless (moose migrate) - Commands for managing migrations manually.
  • Overview
Build a New App
  • 5 Minute Quickstart
  • Browse Templates
  • Existing ClickHouse
Add to Existing App
  • Next.js
  • Fastify
Fundamentals
  • Moose Runtime
  • MooseDev MCP
  • Data Modeling
Moose Modules
  • Moose OLAP
  • Moose Streaming
  • Moose Workflows
  • Moose APIs & Web Apps
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
  • Release Notes
Contribution
  • Documentation
  • Framework