@@ -9,7 +9,9 @@ use std::process::{ChildStderr, Command, Stdio};
9
9
use std:: sync:: Mutex ;
10
10
11
11
use block_id:: { Alphabet , BlockId } ;
12
- use butane_core:: db:: { connect, get_backend, pg, sqlite, Backend , Connection , ConnectionSpec } ;
12
+ use butane_core:: db:: {
13
+ connect, get_backend, pg, sqlite, Backend , BackendConnection , Connection , ConnectionSpec ,
14
+ } ;
13
15
use butane_core:: migrations:: { self , MemMigrations , Migration , Migrations , MigrationsMut } ;
14
16
use once_cell:: sync:: Lazy ;
15
17
use uuid:: Uuid ;
@@ -179,16 +181,15 @@ pub fn pg_connstr(data: &PgSetupData) -> String {
179
181
data. connstr . clone ( )
180
182
}
181
183
182
- /// Populate the database schema.
183
- pub fn setup_db ( backend : Box < dyn Backend > , conn : & mut Connection , migrate : bool ) {
184
+ /// Create a [`MemMigrations`]` for the "current" migration.
185
+ pub fn create_current_migrations ( connection : & Connection ) -> MemMigrations {
186
+ let backend = connection. backend ( ) ;
187
+
184
188
let mut root = std:: env:: current_dir ( ) . unwrap ( ) ;
185
189
root. push ( ".butane/migrations" ) ;
186
190
let mut disk_migrations = migrations:: from_root ( & root) ;
187
191
let disk_current = disk_migrations. current ( ) ;
188
192
log:: info!( "Loading migrations from {:?}" , disk_current) ;
189
- if !migrate {
190
- return ;
191
- }
192
193
// Create an in-memory Migrations and write only to that. This
193
194
// allows concurrent tests to avoid stomping on each other and is
194
195
// also faster than real disk writes.
@@ -208,6 +209,12 @@ pub fn setup_db(backend: Box<dyn Backend>, conn: &mut Connection, migrate: bool)
208
209
. expect( "expected to create migration without error" ) ,
209
210
"expected to create migration"
210
211
) ;
212
+ mem_migrations
213
+ }
214
+
215
+ /// Populate the database schema.
216
+ pub fn setup_db ( conn : & mut Connection ) {
217
+ let mem_migrations = create_current_migrations ( conn) ;
211
218
log:: info!( "created current migration" ) ;
212
219
mem_migrations. migrate ( conn) . unwrap ( ) ;
213
220
}
@@ -240,7 +247,9 @@ macro_rules! maketest {
240
247
let $dataname = butane_test_helper:: [ <$backend _setup>] ( ) ;
241
248
log:: info!( "connecting to {}.." , & $connstr) ;
242
249
let mut conn = backend. connect( & $connstr) . expect( "Could not connect backend" ) ;
243
- butane_test_helper:: setup_db( backend, & mut conn, $migrate) ;
250
+ if $migrate {
251
+ butane_test_helper:: setup_db( & mut conn) ;
252
+ }
244
253
log:: info!( "running test on {}.." , & $connstr) ;
245
254
$fname( conn) ;
246
255
butane_test_helper:: [ <$backend _teardown>] ( $dataname) ;
0 commit comments