File tree Expand file tree Collapse file tree 4 files changed +30
-1
lines changed
migrations_no_tx_reversible Expand file tree Collapse file tree 4 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -207,7 +207,7 @@ CREATE TABLE IF NOT EXISTS {table_name} (
207207 let start = Instant :: now ( ) ;
208208
209209 if migration. no_tx {
210- execute_migration ( self , table_name, migration) . await ?;
210+ revert_migration ( self , table_name, migration) . await ?;
211211 } else {
212212 // Use a single transaction for the actual migration script and the essential bookkeeping so we never
213213 // execute migrations twice. See https://github.com/launchbadge/sqlx/issues/1966.
Original file line number Diff line number Diff 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.
81104async fn clean_up ( conn : & mut SqliteConnection ) -> anyhow:: Result < ( ) > {
82105 conn. execute ( "DROP TABLE migrations_simple_test" ) . await . ok ( ) ;
Original file line number Diff line number Diff line change 1+ -- no-transaction
2+
3+ PRAGMA JOURNAL_MODE = DELETE ;
Original file line number Diff line number Diff line change 1+ -- no-transaction
2+
3+ PRAGMA JOURNAL_MODE = WAL;
You can’t perform that action at this time.
0 commit comments