sqlx/tests/migrate/macro.rs
Marco Neumann 5e56da87e0
fix: ensure migration progress is not lost for PG, mysql and sqlite (#1991)
* fix: ensure migration progress is not lost for PG

Fixes #1966.

* fix: ensure migration progress is not lost for sqlite

This is similar to #1966.

* fix: ensure reverse migration progress is not lost for PG

See #1966.

* fix: ensure reverse migration progress is not lost for sqlite

See #1966.

* fix: ensure migration progress is not lost for mysql

This is similar to #1966.

* fix: ensure reverse migration progress is not lost for mysql

See #1966.

* test: check migration type as well

* test: extend migrations testing

* fix: work around MySQL implicit commits

* refactor: simplify migration testing
2022-09-12 17:52:04 -07:00

30 lines
1.0 KiB
Rust

use sqlx::migrate::Migrator;
use std::path::Path;
static EMBEDDED_SIMPLE: Migrator = sqlx::migrate!("tests/migrate/migrations_simple");
static EMBEDDED_REVERSIBLE: Migrator = sqlx::migrate!("tests/migrate/migrations_reversible");
#[sqlx_macros::test]
async fn same_output() -> anyhow::Result<()> {
let runtime_simple = Migrator::new(Path::new("tests/migrate/migrations_simple")).await?;
let runtime_reversible =
Migrator::new(Path::new("tests/migrate/migrations_reversible")).await?;
assert_same(&EMBEDDED_SIMPLE, &runtime_simple);
assert_same(&EMBEDDED_REVERSIBLE, &runtime_reversible);
Ok(())
}
fn assert_same(embedded: &Migrator, runtime: &Migrator) {
assert_eq!(runtime.migrations.len(), embedded.migrations.len());
for (e, r) in embedded.iter().zip(runtime.iter()) {
assert_eq!(e.version, r.version);
assert_eq!(e.description, r.description);
assert_eq!(e.migration_type, r.migration_type);
assert_eq!(e.sql, r.sql);
assert_eq!(e.checksum, r.checksum);
}
}