#[cfg(feature = "schema-manager-dev")]
mod clear;
mod migrate;
mod rollback;
#[cfg(feature = "schema-manager-dev")]
mod seed;
mod validate;
use crate::{
database::{
Database, DatabaseTy,
executor::Executor,
schema_manager::{DEFAULT_BATCH_SIZE, UserMigration},
},
misc::Lease,
};
#[derive(Debug)]
pub struct Commands<E> {
batch_size: usize,
pub(crate) executor: E,
}
impl<E> Commands<E>
where
E: Executor,
{
#[inline]
pub fn new(batch_size: usize, executor: E) -> Self {
Self { batch_size, executor }
}
#[inline]
pub fn with_executor(database: E) -> Self {
Self { batch_size: DEFAULT_BATCH_SIZE, executor: database }
}
#[inline]
pub fn batch_size(&self) -> usize {
self.batch_size
}
#[inline]
fn filter_by_db<'migration, DBS, I, S>(
migrations: I,
) -> impl Clone + Iterator<Item = &'migration UserMigration<DBS, S>>
where
DBS: Lease<[DatabaseTy]> + 'migration,
I: Clone + Iterator<Item = &'migration UserMigration<DBS, S>>,
S: Lease<str> + 'migration,
{
migrations.filter(move |m| {
if m.dbs().is_empty() { true } else { m.dbs().contains(&<E::Database as Database>::TY) }
})
}
}