Skip to main content

Module migration

Module migration 

Source
Expand description

Schema migration support for database evolution.

This module provides mechanisms to manage database schema changes over time. As applications evolve, their data structures change, and migrations enable safe transformation of existing data.

§Migration Process

A migration:

  1. Defines source and target schema versions
  2. Specifies transformation steps for affected data
  3. Is executed automatically when opening a database with a different schema version

§Creating Migrations

use nitrite::migration::{Migration, MigrationStep};

let migration = Migration::create(1, 2)
    .add_instruction(/* ... */)
    .finalize();

let db = Nitrite::builder()
    .schema_version(2)
    .add_migration(migration)
    .open_or_create(None, None)?;

§Migration Types

  • Collection Instructions: Add/remove collections, create indexes
  • Repository Instructions: Define object repository structure
  • Database Instructions: Global database-level changes

§Atomicity

Migrations are applied atomically - either all changes succeed or none are applied. If a migration fails, the database is rolled back to its previous state.

Structs§

CollectionInstructionBuilder
Builder for collection-level instructions.
DatabaseInstructionBuilder
Builder for database-level instructions.
InstructionSet
Default implementation of InstructionSet
Migration
Abstract base class for user-defined migrations.
MigrationManager
Manages database migrations including version tracking and execution
MigrationStep
Represents a single migration step with its type and arguments.
RepositoryInstructionBuilder
Builder for repository-level instructions.

Enums§

InstructionType
All instruction types supported by the migration system.
MigrationArguments
Type-erased arguments container for migration operations.
MigrationFn
Unified wrapper enum for all migration function closures that can be type-erased and downcasted.

Traits§

CollectionInstruction
Collection-level migration instructions.
DatabaseInstruction
Database-level migration instructions.
Instruction
Base trait for all migration instructions.
RepositoryInstruction
Repository-level migration instructions.