1- use std:: ops:: Deref ;
2-
31use crate :: error:: WrapMigrationError ;
42use crate :: traits:: {
53 insert_migration_query, verify_migrations, ASSERT_MIGRATIONS_TABLE_QUERY ,
@@ -10,10 +8,7 @@ use crate::{Error, Migration, Report, Target};
108pub trait Transaction {
119 type Error : std:: error:: Error + Send + Sync + ' static ;
1210
13- fn execute < ' a , T : Iterator < Item = & ' a str > > (
14- & mut self ,
15- queries : T ,
16- ) -> Result < usize , Self :: Error > ;
11+ fn execute ( & mut self , queries : & [ & str ] ) -> Result < usize , Self :: Error > ;
1712}
1813
1914pub trait Query < T > : Transaction {
@@ -25,7 +20,7 @@ pub fn migrate<T: Transaction>(
2520 migrations : Vec < Migration > ,
2621 target : Target ,
2722 migration_table_name : & str ,
28- grouped : bool ,
23+ batched : bool ,
2924) -> Result < Report , Error > {
3025 let mut migration_batch = Vec :: new ( ) ;
3126 let mut applied_migrations = Vec :: new ( ) ;
@@ -54,7 +49,7 @@ pub fn migrate<T: Transaction>(
5449 migration_batch. push ( insert_migration) ;
5550 }
5651
57- match ( target, grouped ) {
52+ match ( target, batched ) {
5853 ( Target :: Fake | Target :: FakeVersion ( _) , _) => {
5954 log:: info!( "not going to apply any migration as fake flag is enabled" ) ;
6055 }
@@ -73,14 +68,16 @@ pub fn migrate<T: Transaction>(
7368 }
7469 } ;
7570
76- if grouped {
71+ let refs: Vec < & str > = migration_batch. iter ( ) . map ( AsRef :: as_ref) . collect ( ) ;
72+
73+ if batched {
7774 transaction
78- . execute ( migration_batch . iter ( ) . map ( Deref :: deref ) )
75+ . execute ( refs . as_ref ( ) )
7976 . migration_err ( "error applying migrations" , None ) ?;
8077 } else {
81- for ( i, update) in migration_batch . into_iter ( ) . enumerate ( ) {
78+ for ( i, update) in refs . iter ( ) . enumerate ( ) {
8279 transaction
83- . execute ( [ update. as_str ( ) ] . into_iter ( ) )
80+ . execute ( & [ update] )
8481 . migration_err ( "error applying update" , Some ( & applied_migrations[ 0 ..i / 2 ] ) ) ?;
8582 }
8683 }
@@ -108,10 +105,8 @@ where
108105 fn assert_migrations_table ( & mut self , migration_table_name : & str ) -> Result < usize , Error > {
109106 // Needed cause some database vendors like Mssql have a non sql standard way of checking the migrations table,
110107 // thou on this case it's just to be consistent with the async trait `AsyncMigrate`
111- self . execute (
112- [ Self :: assert_migrations_table_query ( migration_table_name) . as_str ( ) ] . into_iter ( ) ,
113- )
114- . migration_err ( "error asserting migrations table" , None )
108+ self . execute ( & [ Self :: assert_migrations_table_query ( migration_table_name) . as_str ( ) ] )
109+ . migration_err ( "error asserting migrations table" , None )
115110 }
116111
117112 fn get_last_applied_migration (
0 commit comments