wtx/database/schema_manager/
commands.rs1#[cfg(feature = "schema-manager-dev")]
2mod clear;
3mod migrate;
4mod rollback;
5#[cfg(feature = "schema-manager-dev")]
6mod seed;
7mod validate;
8
9use crate::{
10 database::{
11 Database, DatabaseTy,
12 executor::Executor,
13 schema_manager::{DEFAULT_BATCH_SIZE, UserMigration},
14 },
15 misc::Lease,
16};
17
18#[derive(Debug)]
20pub struct Commands<E> {
21 batch_size: usize,
22 pub(crate) executor: E,
23}
24
25impl<E> Commands<E>
26where
27 E: Executor,
28{
29 #[inline]
31 pub fn new(batch_size: usize, executor: E) -> Self {
32 Self { batch_size, executor }
33 }
34
35 #[inline]
39 pub fn with_executor(database: E) -> Self {
40 Self { batch_size: DEFAULT_BATCH_SIZE, executor: database }
41 }
42
43 #[inline]
45 pub fn batch_size(&self) -> usize {
46 self.batch_size
47 }
48
49 #[inline]
50 fn filter_by_db<'migration, DBS, I, S>(
51 migrations: I,
52 ) -> impl Clone + Iterator<Item = &'migration UserMigration<DBS, S>>
53 where
54 DBS: Lease<[DatabaseTy]> + 'migration,
55 I: Clone + Iterator<Item = &'migration UserMigration<DBS, S>>,
56 S: Lease<str> + 'migration,
57 {
58 migrations.filter(move |m| {
59 if m.dbs().is_empty() { true } else { m.dbs().contains(&<E::Database as Database>::TY) }
60 })
61 }
62}