diff --git a/refinery_core/src/drivers/config.rs b/refinery_core/src/drivers/config.rs index bc95b572..639ff108 100644 --- a/refinery_core/src/drivers/config.rs +++ b/refinery_core/src/drivers/config.rs @@ -18,10 +18,7 @@ use std::convert::Infallible; impl Transaction for Config { type Error = Infallible; - fn execute<'a, T: Iterator>( - &mut self, - _queries: T, - ) -> Result { + fn execute(&mut self, _queries: &[&str]) -> Result { Ok(0) } } @@ -36,10 +33,7 @@ impl Query> for Config { impl AsyncTransaction for Config { type Error = Infallible; - async fn execute<'a, T: Iterator + Send>( - &mut self, - _queries: T, - ) -> Result { + async fn execute(&mut self, _queries: &[&str]) -> Result { Ok(0) } } diff --git a/refinery_core/src/drivers/mysql.rs b/refinery_core/src/drivers/mysql.rs index c2947152..33148d94 100644 --- a/refinery_core/src/drivers/mysql.rs +++ b/refinery_core/src/drivers/mysql.rs @@ -43,13 +43,10 @@ fn query_applied_migrations( impl Transaction for Conn { type Error = MError; - fn execute<'a, T: Iterator>( - &mut self, - queries: T, - ) -> Result { + fn execute(&mut self, queries: &[&str]) -> Result { let mut transaction = self.start_transaction(get_tx_opts())?; let mut count = 0; - for query in queries { + for query in queries.iter() { transaction.query_iter(query)?; count += 1; } @@ -61,14 +58,11 @@ impl Transaction for Conn { impl Transaction for PooledConn { type Error = MError; - fn execute<'a, T: Iterator>( - &mut self, - queries: T, - ) -> Result { + fn execute(&mut self, queries: &[&str]) -> Result { let mut transaction = self.start_transaction(get_tx_opts())?; let mut count = 0; - for query in queries { + for query in queries.iter() { transaction.query_iter(query)?; count += 1; } diff --git a/refinery_core/src/drivers/mysql_async.rs b/refinery_core/src/drivers/mysql_async.rs index 3f8aaac2..101ab0ab 100644 --- a/refinery_core/src/drivers/mysql_async.rs +++ b/refinery_core/src/drivers/mysql_async.rs @@ -39,10 +39,7 @@ async fn query_applied_migrations<'a>( impl AsyncTransaction for Pool { type Error = MError; - async fn execute<'a, T: Iterator + Send>( - &mut self, - queries: T, - ) -> Result { + async fn execute(&mut self, queries: &[&str]) -> Result { let mut conn = self.get_conn().await?; let mut options = TxOpts::new(); options.with_isolation_level(Some(IsolationLevel::ReadCommitted)); @@ -50,7 +47,7 @@ impl AsyncTransaction for Pool { let mut transaction = conn.start_transaction(options).await?; let mut count = 0; for query in queries { - transaction.query_drop(query).await?; + transaction.query_drop(*query).await?; count += 1; } transaction.commit().await?; diff --git a/refinery_core/src/drivers/postgres.rs b/refinery_core/src/drivers/postgres.rs index fa4d5b9e..3d177509 100644 --- a/refinery_core/src/drivers/postgres.rs +++ b/refinery_core/src/drivers/postgres.rs @@ -33,13 +33,10 @@ fn query_applied_migrations( impl Transaction for PgClient { type Error = PgError; - fn execute<'a, T: Iterator>( - &mut self, - queries: T, - ) -> Result { + fn execute(&mut self, queries: &[&str]) -> Result { let mut transaction = PgClient::transaction(self)?; let mut count = 0; - for query in queries { + for query in queries.iter() { PgTransaction::batch_execute(&mut transaction, query)?; count += 1; } diff --git a/refinery_core/src/drivers/rusqlite.rs b/refinery_core/src/drivers/rusqlite.rs index 9ee4ced9..9547ba48 100644 --- a/refinery_core/src/drivers/rusqlite.rs +++ b/refinery_core/src/drivers/rusqlite.rs @@ -32,13 +32,10 @@ fn query_applied_migrations( impl Transaction for RqlConnection { type Error = RqlError; - fn execute<'a, T: Iterator>( - &mut self, - queries: T, - ) -> Result { + fn execute(&mut self, queries: &[&str]) -> Result { let transaction = self.transaction()?; let mut count = 0; - for query in queries { + for query in queries.iter() { transaction.execute_batch(query)?; count += 1; } diff --git a/refinery_core/src/drivers/tiberius.rs b/refinery_core/src/drivers/tiberius.rs index 8cab422a..117c6344 100644 --- a/refinery_core/src/drivers/tiberius.rs +++ b/refinery_core/src/drivers/tiberius.rs @@ -46,16 +46,13 @@ where { type Error = Error; - async fn execute<'a, T: Iterator + Send>( - &mut self, - queries: T, - ) -> Result { + async fn execute(&mut self, queries: &[&str]) -> Result { // Tiberius doesn't support transactions, see https://github.com/prisma/tiberius/issues/28 self.simple_query("BEGIN TRAN T1;").await?; let mut count = 0; for query in queries { // Drop the returning `QueryStream<'a>` to avoid compiler complaning regarding lifetimes - if let Err(err) = self.simple_query(query).await.map(drop) { + if let Err(err) = self.simple_query(*query).await.map(drop) { if let Err(err) = self.simple_query("ROLLBACK TRAN T1").await { log::error!("could not ROLLBACK transaction, {}", err); } diff --git a/refinery_core/src/drivers/tokio_postgres.rs b/refinery_core/src/drivers/tokio_postgres.rs index 346cfd7c..ec8bb9c8 100644 --- a/refinery_core/src/drivers/tokio_postgres.rs +++ b/refinery_core/src/drivers/tokio_postgres.rs @@ -35,10 +35,7 @@ async fn query_applied_migrations( impl AsyncTransaction for Client { type Error = PgError; - async fn execute<'a, T: Iterator + Send>( - &mut self, - queries: T, - ) -> Result { + async fn execute(&mut self, queries: &[&str]) -> Result { let transaction = self.transaction().await?; let mut count = 0; for query in queries { diff --git a/refinery_core/src/traits/async.rs b/refinery_core/src/traits/async.rs index 8831041f..fc9e4f75 100644 --- a/refinery_core/src/traits/async.rs +++ b/refinery_core/src/traits/async.rs @@ -12,10 +12,7 @@ use std::string::ToString; pub trait AsyncTransaction { type Error: std::error::Error + Send + Sync + 'static; - async fn execute<'a, T: Iterator + Send>( - &mut self, - queries: T, - ) -> Result; + async fn execute(&mut self, query: &[&str]) -> Result; } #[async_trait] @@ -46,13 +43,10 @@ async fn migrate( migration.set_applied(); let update_query = insert_migration_query(&migration, migration_table_name); transaction - .execute( - [ - migration.sql().as_ref().expect("sql must be Some!"), - update_query.as_str(), - ] - .into_iter(), - ) + .execute(&[ + migration.sql().as_ref().expect("sql must be Some!"), + &update_query, + ]) .await .migration_err( &format!("error applying migration {}", migration), @@ -111,10 +105,10 @@ async fn migrate_grouped( ); } - let refs = grouped_migrations.iter().map(AsRef::as_ref); + let refs: Vec<&str> = grouped_migrations.iter().map(AsRef::as_ref).collect(); transaction - .execute(refs) + .execute(refs.as_ref()) .await .migration_err("error applying migrations", None)?; @@ -172,11 +166,9 @@ where target: Target, migration_table_name: &str, ) -> Result { - self.execute( - [Self::assert_migrations_table_query(migration_table_name).as_str()].into_iter(), - ) - .await - .migration_err("error asserting migrations table", None)?; + self.execute(&[&Self::assert_migrations_table_query(migration_table_name)]) + .await + .migration_err("error asserting migrations table", None)?; let applied_migrations = self .get_applied_migrations(migration_table_name) diff --git a/refinery_core/src/traits/sync.rs b/refinery_core/src/traits/sync.rs index bf761035..23cc7a90 100644 --- a/refinery_core/src/traits/sync.rs +++ b/refinery_core/src/traits/sync.rs @@ -1,5 +1,3 @@ -use std::ops::Deref; - use crate::error::WrapMigrationError; use crate::traits::{ insert_migration_query, verify_migrations, ASSERT_MIGRATIONS_TABLE_QUERY, @@ -10,10 +8,7 @@ use crate::{Error, Migration, Report, Target}; pub trait Transaction { type Error: std::error::Error + Send + Sync + 'static; - fn execute<'a, T: Iterator>( - &mut self, - queries: T, - ) -> Result; + fn execute(&mut self, queries: &[&str]) -> Result; } pub trait Query: Transaction { @@ -25,7 +20,7 @@ pub fn migrate( migrations: Vec, target: Target, migration_table_name: &str, - grouped: bool, + batched: bool, ) -> Result { let mut migration_batch = Vec::new(); let mut applied_migrations = Vec::new(); @@ -54,7 +49,7 @@ pub fn migrate( migration_batch.push(insert_migration); } - match (target, grouped) { + match (target, batched) { (Target::Fake | Target::FakeVersion(_), _) => { log::info!("not going to apply any migration as fake flag is enabled"); } @@ -73,14 +68,16 @@ pub fn migrate( } }; - if grouped { + let refs: Vec<&str> = migration_batch.iter().map(AsRef::as_ref).collect(); + + if batched { transaction - .execute(migration_batch.iter().map(Deref::deref)) + .execute(refs.as_ref()) .migration_err("error applying migrations", None)?; } else { - for (i, update) in migration_batch.into_iter().enumerate() { + for (i, update) in refs.iter().enumerate() { transaction - .execute([update.as_str()].into_iter()) + .execute(&[update]) .migration_err("error applying update", Some(&applied_migrations[0..i / 2]))?; } } @@ -108,10 +105,8 @@ where fn assert_migrations_table(&mut self, migration_table_name: &str) -> Result { // Needed cause some database vendors like Mssql have a non sql standard way of checking the migrations table, // thou on this case it's just to be consistent with the async trait `AsyncMigrate` - self.execute( - [Self::assert_migrations_table_query(migration_table_name).as_str()].into_iter(), - ) - .migration_err("error asserting migrations table", None) + self.execute(&[Self::assert_migrations_table_query(migration_table_name).as_str()]) + .migration_err("error asserting migrations table", None) } fn get_last_applied_migration(