We value your privacy

This site uses cookies to improve your browsing experience, analyze site traffic, and show personalized content. See our Privacy Policy.

  1. MooseStack
  2. Moose Migrate
  3. Automatic Migrations

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 can drop columns containing data if a field is removed in the code. While column renames are now detected and confirmed interactively, production deployments should always use planned migrations.

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

By default, moose prod blocks startup when destructive changes are detected without a reviewed plan.yaml. See Production Safety Gate for details. To override at runtime without changing config, set MOOSE_MIGRATION_CONFIG__PROD_AUTO_ALLOW_DESTRUCTIVE=true.

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 FieldRename (with confirmation)ALTER TABLE ... RENAME COLUMN old TO newSafe (if confirmed as rename)
Remove TableDrop TableDROP TABLE ...Destructive

Confirmation Prompts

Column Rename Detection

When you rename a field, Moose uses heuristic analysis (name similarity, type matching) to detect likely renames. Instead of silently dropping the old column and adding a new one, it prompts you:

Rename (1/1): `events`.`user_id` → `uid` (confidence: 0.82)  y=rename  n=drop+create  c=cancel
  • y (default): Apply as a RENAME COLUMN — data is preserved.
  • n: Treat as a destructive drop + add — old column data is lost.
  • c: Cancel the entire change cycle.

To skip prompts and auto-accept all renames, pass --yes-rename or set MOOSE_ACCEPT_RENAME=1.

Destructive Operations

When the detected changes contain destructive operations (table drops, column removals, view removals, materialized view removals, table recreates), Moose pauses and asks for confirmation before proceeding:

⚠  1 destructive change(s) — type y to accept, n to reject

If you reject, the change cycle is skipped — your code change stays, and Moose will re-prompt on the next file save. To skip destructive prompts, pass --yes-destructive or set MOOSE_ACCEPT_DESTRUCTIVE=1. Use --yes-all to skip both rename and destructive prompts.

Production deployments

Even with confirmation prompts, automatic migrations are not recommended for production. Use Planned Migrations for reviewed, safe schema changes.

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.

On this page

CommandProduction UsageBehaviorOperation ReferenceConfirmation PromptsColumn Rename DetectionDestructive OperationsConfigurationCLI Output ReferenceExample OutputSee Also
Edit this page
FiveonefourFiveonefour
Fiveonefour Docs
MooseStackHostingTemplatesGuides
Release Notes
Source564
  • Overview
Build a New App
  • 5 Minute Quickstart
  • Browse Templates
  • Existing ClickHouse
Add to Existing App
  • Next.js
  • Fastify
Fundamentals
  • Moose Runtime
  • MooseDev MCP
  • Language Server
  • Data Modeling
Moose Modules
  • Moose OLAP
  • Moose Streaming
  • Moose Workflows
  • Moose APIs & Web Apps
Deployment & Lifecycle
  • Moose Dev
  • 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
  • Query Layer
  • Testing Utilities
  • Data Types
  • Table Engines
  • CLI
  • Configuration
  • Observability Metrics
  • Help
  • Release Notes
Contribution
  • Documentation
  • Framework