1+ use std:: ops:: Deref ;
2+
13use crate :: error:: WrapMigrationError ;
24use crate :: traits:: {
35 insert_migration_query, verify_migrations, ASSERT_MIGRATIONS_TABLE_QUERY ,
@@ -8,7 +10,10 @@ use crate::{Error, Migration, Report, Target};
810pub trait Transaction {
911 type Error : std:: error:: Error + Send + Sync + ' static ;
1012
11- fn execute ( & mut self , queries : & [ & str ] ) -> Result < usize , Self :: Error > ;
13+ fn execute < ' a , T : Iterator < Item = & ' a str > > (
14+ & mut self ,
15+ queries : T ,
16+ ) -> Result < usize , Self :: Error > ;
1217}
1318
1419pub trait Query < T > : Transaction {
@@ -20,7 +25,7 @@ pub fn migrate<T: Transaction>(
2025 migrations : Vec < Migration > ,
2126 target : Target ,
2227 migration_table_name : & str ,
23- batched : bool ,
28+ grouped : bool ,
2429) -> Result < Report , Error > {
2530 let mut migration_batch = Vec :: new ( ) ;
2631 let mut applied_migrations = Vec :: new ( ) ;
@@ -49,7 +54,7 @@ pub fn migrate<T: Transaction>(
4954 migration_batch. push ( insert_migration) ;
5055 }
5156
52- match ( target, batched ) {
57+ match ( target, grouped ) {
5358 ( Target :: Fake | Target :: FakeVersion ( _) , _) => {
5459 log:: info!( "not going to apply any migration as fake flag is enabled" ) ;
5560 }
@@ -68,16 +73,14 @@ pub fn migrate<T: Transaction>(
6873 }
6974 } ;
7075
71- let refs: Vec < & str > = migration_batch. iter ( ) . map ( AsRef :: as_ref) . collect ( ) ;
72-
73- if batched {
76+ if grouped {
7477 transaction
75- . execute ( refs . as_ref ( ) )
78+ . execute ( migration_batch . iter ( ) . map ( Deref :: deref ) )
7679 . migration_err ( "error applying migrations" , None ) ?;
7780 } else {
78- for ( i, update) in refs . iter ( ) . enumerate ( ) {
81+ for ( i, update) in migration_batch . into_iter ( ) . enumerate ( ) {
7982 transaction
80- . execute ( & [ update] )
83+ . execute ( [ update. as_str ( ) ] . into_iter ( ) )
8184 . migration_err ( "error applying update" , Some ( & applied_migrations[ 0 ..i / 2 ] ) ) ?;
8285 }
8386 }
@@ -92,10 +95,13 @@ where
9295 fn assert_migrations_table ( & mut self , migration_table_name : & str ) -> Result < usize , Error > {
9396 // Needed cause some database vendors like Mssql have a non sql standard way of checking the migrations table,
9497 // thou on this case it's just to be consistent with the async trait `AsyncMigrate`
95- self . execute ( & [ ASSERT_MIGRATIONS_TABLE_QUERY
96- . replace ( "%MIGRATION_TABLE_NAME%" , migration_table_name)
97- . as_str ( ) ] )
98- . migration_err ( "error asserting migrations table" , None )
98+ self . execute (
99+ [ ASSERT_MIGRATIONS_TABLE_QUERY
100+ . replace ( "%MIGRATION_TABLE_NAME%" , migration_table_name)
101+ . as_str ( ) ]
102+ . into_iter ( ) ,
103+ )
104+ . migration_err ( "error asserting migrations table" , None )
99105 }
100106
101107 fn get_last_applied_migration (
0 commit comments