Skip to content

Commit 1ee9ca6

Browse files
author
Markus Gasser
committed
Add regression test
1 parent e1ed875 commit 1ee9ca6

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

tests/sqlite/migrate.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,29 @@ async fn no_tx(mut conn: PoolConnection<Sqlite>) -> anyhow::Result<()> {
7777
Ok(())
7878
}
7979

80+
#[sqlx::test(migrations = false)]
81+
async fn no_tx_reversible(mut conn: PoolConnection<Sqlite>) -> anyhow::Result<()> {
82+
clean_up(&mut conn).await?;
83+
84+
let migrator = Migrator::new(Path::new("tests/sqlite/migrations_no_tx_reversible")).await?;
85+
86+
// run migration
87+
migrator.run(&mut conn).await?;
88+
89+
// check outcome
90+
let res: String = conn.fetch_one("PRAGMA JOURNAL_MODE").await?.get(0);
91+
assert_eq!(res, "wal".to_string());
92+
93+
// roll back
94+
migrator.undo(&mut conn, -1).await?;
95+
96+
// check outcome
97+
let res: String = conn.fetch_one("PRAGMA JOURNAL_MODE").await?.get(0);
98+
assert_eq!(res, "delete".to_string());
99+
100+
Ok(())
101+
}
102+
80103
/// Ensure that we have a clean initial state.
81104
async fn clean_up(conn: &mut SqliteConnection) -> anyhow::Result<()> {
82105
conn.execute("DROP TABLE migrations_simple_test").await.ok();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- no-transaction
2+
3+
PRAGMA JOURNAL_MODE = DELETE;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- no-transaction
2+
3+
PRAGMA JOURNAL_MODE = WAL;

0 commit comments

Comments
 (0)