see-migration-test-helpers

Crates.iosee-migration-test-helpers
lib.rssee-migration-test-helpers
version1.0.1
created_at2026-01-15 21:46:13.721027+00
updated_at2026-01-16 09:37:38.746192+00
descriptionHelper types for sea-orm-migration testing
homepagehttps://github.com/bragov4ik/see-migration-test-helpers
repository
max_upload_size
id2047157
size41,486
Kirill Ivanov (bragov4ik)

documentation

README

see-migration-test-helpers

Helper types for testing sea-orm-migration migrations in isolation.

Elements

  • MigratorBeforeTested - Run migrations up to (but not including) a specific migration
  • MigratorWithTested - Run migrations including a specific migration
  • EmptyStruct derive macro - Automatically implement the EmptyStruct trait for unit structs (needed for using MigratorBeforeTested/MigratorWithTested)

Usage

Add to your Cargo.toml:

[dependencies]
see-migration-test-helpers = "1"

Example

use see_migration_test_helpers::{MigratorBeforeTested, MigratorWithTested};

// Define type aliases for your test
type MigratorBefore = MigratorBeforeTested<crate::Migrator, super::Migration>;
type MigratorAfter = MigratorWithTested<crate::Migrator, super::Migration>;

#[async_std::test]
async fn test_my_migration() {
    // Set up database with all migrations before the one being tested
    let db = {
        () // Setup connection
    };
    MigratorBefore::up(&db, None)
        .await
        .expect("Initial migration failed");
    
    // Insert test data that should exist before the migration
    db.execute_unprepared("INSERT INTO users (id, email) VALUES (1, 'test@example.com')")
        .await
        .unwrap();
    
    // Run the migration being tested
    MigratorAfter::up(&db, None)
        .await
        .expect("Migration failed");
    
    // Verify the migration worked correctly
    // ... your assertions ...
    
    // Test rollback
    MigratorAfter::down(&db, Some(1))
        .await
        .expect("Rollback failed");
}

Migration Requirements

Your migration struct must implement EmptyStruct. Use the derive macro:

use see_migration_test_helpers::EmptyStruct;

#[derive(EmptyStruct)]
pub struct m20240101_000001_create_users;

// ... migration implementation ...

License

MIT

Commit count: 0

cargo fmt