Docs.rs
  • mongodb-migrator-0.1.8
    • mongodb-migrator 0.1.8
    • Permalink
    • Docs.rs crate page
    • MIT OR Apache-2.0
    • Links
    • Repository
    • crates.io
    • Source
    • Owners
    • kakoc
    • Dependencies
      • anyhow ^1.0.34 normal
      • async-trait ^0.1.42 normal
      • axum ^0.6.1 normal
      • bson ^2.3.0 normal
      • chrono ^0.4.19 normal
      • futures ^0.3.8 normal
      • log ^0.4.11 normal
      • mongodb ^2.2.2 normal
      • serde ^1.0.117 normal
      • serde_derive ^1.0.117 normal
      • serde_json ^1.0.82 normal
      • thiserror ^1.0.31 normal
      • tokio ^1.17.0 normal
      • tracing ^0.1.37 normal
      • tracing-subscriber ^0.3.16 normal
      • hyper ^0.14.23 dev
      • rusty-hook ^0.11.2 dev
      • testcontainers ^0.11.0 dev
      • version-sync ^0.9 dev
    • Versions
    • 14.85% of the crate is documented
  • Platform
    • i686-unknown-linux-gnu
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation

Crate mongodb_migrator

mongodb_migrator0.1.8

  • All Items

Sections

  • Example

Crate Items

  • Modules

Crates

  • mongodb_migrator

Crate mongodb_migrator

Source
Expand description

This crate provides a convinient way of how to manage migrations.
It’s inteded to be used as a library: You maintain all migrations by your own via implementing migration::Migration trait
and pass a sequence of migrations to the migrator::Migrator on every bootstrap of your system

§Example

use anyhow::Result;
use async_trait::async_trait;
use mongodb::Database;
use serde_derive::{Deserialize, Serialize};
use testcontainers::Docker;

use mongodb_migrator::{migration::Migration, migrator::Env};

#[tokio::main]
async fn main() -> Result<()> {
    let docker = testcontainers::clients::Cli::default();
    let node = docker.run(testcontainers::images::mongo::Mongo::default());
    let host_port = node.get_host_port(27017).unwrap();
    let url = format!("mongodb://localhost:{}/", host_port);
    let client = mongodb::Client::with_uri_str(url).await.unwrap();
    let db = client.database("test");

    let migrations: Vec<Box<dyn Migration>> = vec![Box::new(M0 {}), Box::new(M1 {})];
    mongodb_migrator::migrator::default::DefaultMigrator::new()
        .with_conn(db.clone())
        .with_migrations_vec(migrations)
        .up()
        .await?;

    Ok(())
}

struct M0 {}
struct M1 {}

#[async_trait]
impl Migration for M0 {
    async fn up(&self, env: Env) -> Result<()> {
        env.db.expect("db is available").collection("users")
            .insert_one(bson::doc! { "name": "Batman" }, None)
            .await?;

        Ok(())
    }
}

#[async_trait]
impl Migration for M1 {
    async fn up(&self, env: Env) -> Result<()> {
        env.db.expect("db is available").collection::<Users>("users")
            .update_one(
                bson::doc! { "name": "Batman" },
                bson::doc! { "$set": { "name": "Superman" } },
                None,
            )
            .await?;

        Ok(())
    }
}

#[derive(Serialize, Deserialize)]
struct Users {
    name: String,
}

Modules§

error
migration
In order to treat the entity as migrationable it should implement Migration trait
migration_record
MigrationRecord describes the document which will be stored in the migrations collection.
It contains all useful attributes which might be used in order to understand the current state of a particular migration
migration_status
Describes a migration status
migrator
Migrator runs passed migrations - entities which implement [Migration] trait
server

Results

Settings
Help
    trait
    mongodb_migrator::migration::Migration
    module
    mongodb_migrator::migration
    In order to treat the entity as migrationable it should …
    struct field
    mongodb_migrator::migrator::with_migrations_vec::WithMigrationsVec::migrations
    struct field
    mongodb_migrator::server::MigratorParams::migrations
    struct field
    mongodb_migrator::error::MigrationExecution::InitialMigrationRecord::migration_id
    struct field
    mongodb_migrator::error::MigrationExecution::InProgressStatusNotSaved::migration_id
    struct field
    mongodb_migrator::error::MigrationExecution::FinishedButNotSavedDueToSerialization::migration_id
    struct field
    mongodb_migrator::error::MigrationExecution::FinishedButNotSavedDueMongoError::migration_id
    struct field
    mongodb_migrator::error::MigrationExecution::FinishedAndSavedAsFail::migration_id
    struct field
    mongodb_migrator::error::MigrationExecution::MigrationFromVecNotFound::migration_id
    method
    mongodb_migrator::migration_record::MigrationRecord::migration_start
    struct
    mongodb_migrator::migration_record::MigrationRecord
    enum
    mongodb_migrator::migration_status::MigrationStatus
    method
    mongodb_migrator::migration_record::MigrationRecord::migration_failed
    module
    mongodb_migrator::migration_record
    MigrationRecord describes the document which will be stored
    struct field
    mongodb_migrator::error::MigrationExecution::InitialMigrationRecord::migration_record
    struct field
    mongodb_migrator::error::MigrationExecution::FinishedButNotSavedDueToSerialization::migration_record
    module
    mongodb_migrator::migration_status
    Describes a migration status
    struct field
    mongodb_migrator::error::MigrationExecution::FinishedButNotSavedDueToSerialization::migration_status
    struct field
    mongodb_migrator::error::MigrationExecution::FinishedButNotSavedDueMongoError::migration_status
    enum
    mongodb_migrator::error::MigrationExecution
    method
    mongodb_migrator::migration_record::MigrationRecord::migration_succeeded
    enum variant
    mongodb_migrator::error::MigrationExecution::MigrationFromVecNotFound
    struct
    mongodb_migrator::migrator::with_migrations_vec::WithMigrationsVec
    enum variant
    mongodb_migrator::migrator::Migrator::WithMigrationsVec
    module
    mongodb_migrator::migrator::with_migrations_vec
    method
    mongodb_migrator::migrator::with_connection::WithConnection::with_migrations_vec
    method
    mongodb_migrator::migrator::with_shell_config::WithShellConfig::with_migrations_vec
    enum variant
    mongodb_migrator::error::MigrationExecution::PassedMigrationsWithDuplicatedIds
    enum variant
    mongodb_migrator::error::MigrationExecution::InitialMigrationRecord
    struct field
    mongodb_migrator::error::MigrationExecution::InitialMigrationRecord::next_not_executed_migrations_ids
    struct field
    mongodb_migrator::error::MigrationExecution::InProgressStatusNotSaved::next_not_executed_migrations_ids
    struct field
    mongodb_migrator::error::MigrationExecution::FinishedButNotSavedDueToSerialization::next_not_executed_migrations_ids
    struct field
    mongodb_migrator::error::MigrationExecution::FinishedButNotSavedDueMongoError::next_not_executed_migrations_ids
    struct field
    mongodb_migrator::error::MigrationExecution::FinishedAndSavedAsFail::next_not_executed_migrations_ids
    module
    mongodb_migrator::migrator
    Migrator runs passed migrations - entities which implement …
    enum
    mongodb_migrator::migrator::Migrator
    struct field
    mongodb_migrator::server::ServiceParams::migrator
    method
    mongodb_migrator::migration::Migration::get_id
    &Migration -> &str
    A status about a migration will be stored in a db …
    trait method
    mongodb_migrator::migration::Migration::up
    &Migration, Env -> Pin<Box<Future>>
    Runs a migration.
    method
    mongodb_migrator::migration::Migration::down
    &Migration, Env -> Pin<Box<Future>>
    Rollbacks a migration. Since not every migration could be …
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.