Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sqlx-sqlite/src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ CREATE TABLE IF NOT EXISTS {table_name} (
let start = Instant::now();

if migration.no_tx {
execute_migration(self, table_name, migration).await?;
revert_migration(self, table_name, migration).await?;
} else {
// Use a single transaction for the actual migration script and the essential bookkeeping so we never
// execute migrations twice. See https://github.com/launchbadge/sqlx/issues/1966.
Expand Down
23 changes: 23 additions & 0 deletions tests/sqlite/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,29 @@ async fn no_tx(mut conn: PoolConnection<Sqlite>) -> anyhow::Result<()> {
Ok(())
}

#[sqlx::test(migrations = false)]
async fn no_tx_reversible(mut conn: PoolConnection<Sqlite>) -> anyhow::Result<()> {
clean_up(&mut conn).await?;

let migrator = Migrator::new(Path::new("tests/sqlite/migrations_no_tx_reversible")).await?;

// run migration
migrator.run(&mut conn).await?;

// check outcome
let res: String = conn.fetch_one("PRAGMA JOURNAL_MODE").await?.get(0);
assert_eq!(res, "wal".to_string());

// roll back
migrator.undo(&mut conn, -1).await?;

// check outcome
let res: String = conn.fetch_one("PRAGMA JOURNAL_MODE").await?.get(0);
assert_eq!(res, "delete".to_string());

Ok(())
}

/// Ensure that we have a clean initial state.
async fn clean_up(conn: &mut SqliteConnection) -> anyhow::Result<()> {
conn.execute("DROP TABLE migrations_simple_test").await.ok();
Expand Down
3 changes: 3 additions & 0 deletions tests/sqlite/migrations_no_tx_reversible/0_vacuum.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- no-transaction

PRAGMA JOURNAL_MODE = DELETE;
3 changes: 3 additions & 0 deletions tests/sqlite/migrations_no_tx_reversible/0_vacuum.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- no-transaction

PRAGMA JOURNAL_MODE = WAL;
Loading