Overview
Snuba uses a migration system to manage ClickHouse database schema changes. The migration commands provide tools for listing, running, and reverting migrations across different storage groups. Migrations are organized into migration groups that correspond to different parts of the system (e.g.,events, transactions, system). Each migration group can have its own readiness state that determines when it should be applied.
Main Command
Subcommands
list
Lists all migrations and their current status across all migration groups.- All migration groups with their readiness states
- Migration IDs within each group
- Status indicators:
[X]- Completed[ ]- Not started[-]- In progress
- Blocking status for incomplete migrations
- Warnings for migrations that no longer exist in code
Example Output
migrate
Runs pending migrations for a specific group or all groups.Run migrations up to and including this migration ID. Use
"all" to run all pending migrations.Migration group to run migrations for. If not specified, runs migrations for all groups.Common groups:
system- Core system tablesevents- Error events storagetransactions- Transaction events storageoutcomes- Outcomes/billing datasessions- Session datametrics- Metrics storage
Only run migrations for groups with specific readiness states. Can be specified multiple times.Available states:
complete- Fully ready for productionlimited- Limited availabilityexperimental- Experimental featurespartial- Partially implemented
Force running of blocking migrations. Required for migrations marked as blocking.
Mark migrations as completed without actually running them. Useful for fixing migration state.
Check for dangerous operations (like dropping tables or columns) and require confirmation.
Logging level (critical, error, warning, info, debug, notset).
Examples
run
Runs a single specific migration.Migration group containing the migration.
ID of the migration to run.
Required to run blocking migrations.
Mark migration as completed without running. Requires confirmation unless
--yes is also passed.Show what SQL would be executed without actually running it.
Skip confirmation prompts (use with caution).
Check for dangerous operations and require confirmation.
Logging level to use.
Examples
Migrations that are already in progress or completed will not be run again. Use
--fake to fix migration state if needed.revert
Reverses migrations for a group, running them backwards.Revert migrations back to and including this migration ID. Use
"all" to revert all migrations.Migration group to revert migrations for. If not specified, reverts migrations for all groups.
Only revert migrations for groups with specific readiness states.
Required to perform revert operations.
Mark migrations as reverted without actually running the reverse operations.
Also revert SYSTEM migrations. By default, system migrations are NOT reversed.
Logging level to use.
Examples
reverse
Reverses a single specific migration.Migration group containing the migration.
ID of the migration to reverse.
Required to reverse an already completed migration.
Mark migration as reversed without running. Requires confirmation unless
--yes is passed.Show what SQL would be executed without running it.
Skip confirmation prompts.
Logging level to use.
Examples
reverse-in-progress
Reverses any migrations currently in an “in progress” state.Only reverse in-progress migrations for this group. If not specified, checks all groups.
Mark migrations as reversed without running. Requires confirmation unless
--yes is passed.Show which migrations would be reversed without executing.
Skip confirmation prompts.
Logging level to use.
Examples
This command is useful for recovering from failed migrations that left the system in an in-progress state.
generate
Generates a new migration file based on schema changes in a storage definition.Path to the modified storage YAML definition file.Must match pattern:
snuba/datasets/configuration/.*/storages/.*.(yml|yaml)Optional name for the generated migration. If not provided, a default name is generated.
How It Works
- Modify Storage YAML - Edit the storage definition file to add/modify schema
- Leave Uncommitted - The changes must be uncommitted in your working directory
- Run Generate - Command analyzes the diff between HEAD and working directory
- Migration Created - A Python migration file is generated in the appropriate directory
Currently only column addition is supported for automatic generation. Other schema changes require manual migration creation.
Examples
Migration Groups and Readiness States
Common Migration Groups
- system - Core system tables for storing migration status
- events - Error and exception events
- transactions - Transaction/span events
- outcomes - Outcome and billing data
- sessions - Session aggregates
- metrics - Metrics data (various types)
- querylog - Query logs and performance data
- profiles - Profiling data
- replays - Session replay data
Readiness States
complete
complete
Fully implemented and production-ready. Safe to run in all environments.
limited
limited
Limited availability or partial rollout. May be enabled only for certain tenants.
experimental
experimental
Experimental features under active development. Use with caution.
partial
partial
Partially implemented functionality. May be missing features or optimizations.
Migration Status
Migrations can be in one of three states:- NOT_STARTED - Migration has not been applied
- IN_PROGRESS - Migration is currently running (or was interrupted)
- COMPLETED - Migration was successfully applied
Best Practices
Before Running Migrations
Review Migration Code
Always review the migration code before running, especially for blocking migrations.
Running Migrations in Production
Handling Failed Migrations
Migration Stuck in IN_PROGRESS
Migration Stuck in IN_PROGRESS
If a migration is interrupted:
Migration Applied Manually
Migration Applied Manually
If you manually applied schema changes:
Need to Rollback
Need to Rollback
To rollback a completed migration:
Connection Requirements
All migration commands (except
generate with --dry-run) check ClickHouse connections before executing. Ensure ClickHouse clusters are accessible before running migrations.- All clusters (for
migrateandrevertwithout specific group) - Specific clusters for the migration group (when
--groupis specified) - Clusters matching readiness states (when
--readiness-stateis used)
Monitoring Migrations
Check Migration Status
Verbose Logging
Use debug logging to monitor migration execution:Common Workflows
Initial Setup
Deploying New Features
Developing New Migrations
See Also
- MIGRATIONS.md in the repository root for detailed migration development guide
- Migration Runner source code:
snuba/migrations/runner.py - Migration Groups definition:
snuba/migrations/groups.py