1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
mod migration;
mod migrator_inner;
mod model;

pub use {
    migration::{Migration, MigrationList, Version},
    migrator_inner::Migrator,
};

#[macro_export]
macro_rules! simple_migration {
    ($name:ident, $up:literal, $down:literal) => {
        struct $name;

        impl<S: mysql_connector::Socket> mysql_connector::migrator::Migration<S> for $name {
            fn name(&self) -> &'static str {
                stringify!($name)
            }

            fn up<'a>(
                &self,
                conn: &'a mut mysql_connector::Connection<S>,
            ) -> std::pin::Pin<
                Box<
                    dyn std::future::Future<Output = Result<(), mysql_connector::error::Error>>
                        + 'a,
                >,
            > {
                Box::pin(async { conn.execute_query($up).await.map(|_| {}) })
            }

            fn down<'a>(
                &self,
                conn: &'a mut mysql_connector::Connection<S>,
            ) -> std::pin::Pin<
                Box<
                    dyn std::future::Future<Output = Result<(), mysql_connector::error::Error>>
                        + 'a,
                >,
            > {
                Box::pin(async { conn.execute_query($down).await.map(|_| {}) })
            }
        }
    };
}