Migrations

Run long-running data migrations on live Convex databases with progress tracking, error handling, and zero-downtime deployment support.

Installation

npm install @convex-dev/migrations

About Migrations

A migrations component for Convex. Define, run, and track your database migrations. Run from a CLI or Convex server function

Migrations allow you to define functions that run on all documents in a table (or a specified subset). They run in batches asynchronously (online migration).

The component tracks the migrations state so it can avoid running twice, pick up where it left off (in the case of a bug or failure along the way), and expose the migration state in realtime via Convex queries.

See the migration primer post for a conceptual overview of online vs. offline migrations. If your migration is trivial and you're moving fast, also check out lightweight migrations in the dashboard.

Benefits

Use cases

how to migrate large datasets in Convex without downtime

The @convex-dev/migrations component provides a framework for running incremental data migrations on live Convex databases. It processes records in batches, tracks progress, and allows the database to remain available during the migration process.

Convex schema migration with rollback support

This component includes built-in rollback capabilities for schema migrations, allowing you to safely test changes in production. You can define forward and backward migration functions that maintain referential integrity throughout the process.

batch processing large data transformations Convex

The migrations framework handles large datasets by processing records in configurable batches, preventing function timeouts and memory issues. It automatically resumes from the last processed record if interrupted.

production database migration monitoring Convex

The component provides real-time progress tracking and error reporting for migration jobs. You can monitor the status of running migrations and receive detailed logs about processed records and any failures.

Frequently asked questions

How does the Convex migrations component handle function timeouts during large migrations?

The @convex-dev/migrations component processes data in configurable batches to stay within Convex function execution limits. It automatically saves progress after each batch and resumes from the last checkpoint if a timeout occurs, ensuring no data is lost or processed twice.

Can I rollback a migration that's already partially completed?

Yes, the migrations component supports rollback functionality for partially completed migrations. You define both forward and backward migration functions, and the framework tracks which records have been processed to safely reverse changes without affecting the entire dataset.

What happens if my migration fails on some records but succeeds on others?

The @convex-dev/migrations component tracks the success and failure of individual records or batches. Failed records are logged with error details, while successful ones are marked as complete. You can retry failed records or investigate issues without reprocessing successful migrations.

How do I monitor the progress of a running migration in production?

The migrations component provides built-in progress tracking that shows the number of records processed, remaining work, and estimated completion time. You can query migration status through the framework's API and integrate it with your monitoring tools.

Is it safe to deploy new code while a migration is running?

The @convex-dev/migrations component is designed for zero-downtime deployments. Migration state is persisted in the database, so deployments won't interrupt running migrations. The framework handles version compatibility and can resume migrations after code updates.

Links