| Crates.io | see-migration-test-helpers |
| lib.rs | see-migration-test-helpers |
| version | 1.0.1 |
| created_at | 2026-01-15 21:46:13.721027+00 |
| updated_at | 2026-01-16 09:37:38.746192+00 |
| description | Helper types for sea-orm-migration testing |
| homepage | https://github.com/bragov4ik/see-migration-test-helpers |
| repository | |
| max_upload_size | |
| id | 2047157 |
| size | 41,486 |
Helper types for testing sea-orm-migration migrations in isolation.
MigratorBeforeTested - Run migrations up to (but not including) a specific migrationMigratorWithTested - Run migrations including a specific migrationEmptyStruct derive macro - Automatically implement the EmptyStruct trait for unit structs (needed for using MigratorBeforeTested/MigratorWithTested)Add to your Cargo.toml:
[dependencies]
see-migration-test-helpers = "1"
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");
}
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 ...
MIT