pub fn generate(
    migrations_dir: impl AsRef<Path>,
    module_path: impl AsRef<Path>,
    db_type: DatabaseType,
) {
    cargo_rerun(migrations_dir.as_ref());

    let modules = super::migration_modules(migrations_dir.as_ref());
    let migrations = super::migrations(db_type, migrations_dir.as_ref());

    if let Some(p) = module_path.as_ref().parent() {
        fs::create_dir_all(p).unwrap();
    }

    let db_ident = Ident::new(db_type.sqlx_type(), Span::call_site());

    fs::write(
        module_path,
        quote! {
            pub use sqlx_migrate::prelude::*;

            #modules

            /// All the migrations.
            pub fn migrations() -> impl IntoIterator<Item = Migration<sqlx::#db_ident>> {
                #migrations
            }

        }
        .to_string(),
    )
    .unwrap();
}
/// Generate Rust code from a migrations directory.
/// It is meant to be used in `build.rs`.
/// 
/// # Panics
///
/// This function is meant to be used in `build.rs` and will panic on errors.
Generate Rust code from a migrations directory.
It is meant to be used in `build.rs`.
Generate Rust code from a migrations directory . It is meant to be used in ` build . rs ` .
pub fn generate(
    migrations_dir: impl AsRef<Path>,
    module_path: impl AsRef<Path>,
    db_type: DatabaseType,
) {
    cargo_rerun(migrations_dir.as_ref());
    let modules = super::migration_modules(migrations_dir.as_ref());
    let migrations = super::migrations(db_type, migrations_dir.as_ref());
    if let Some(p) = module_path.as_ref().parent() {
        fs::create_dir_all(p).unwrap();
    }
    let db_ident = Ident::new(db_type.sqlx_type(), Span::call_site());
    fs::write(
        module_path,
        quote! {
            pub use sqlx_migrate::prelude::*;
            #modules
            /// All the migrations.
            pub fn migrations() -> impl IntoIterator<Item = Migration<sqlx::#db_ident>> {
                #migrations
            }
        }
        .to_string(),
    )
    .unwrap();
}
pub fn generate ( migrations_dir : impl AsRef < Path > , module_path : impl AsRef < Path > , db_type : DatabaseType , ) { cargo_rerun ( migrations_dir . as_ref ( ) ) ; let modules = super :: migration_modules ( migrations_dir . as_ref ( ) ) ; let migrations = super :: migrations ( db_type , migrations_dir . as_ref ( ) ) ; if let Some ( p ) = module_path . as_ref ( ) . parent ( ) { fs :: create_dir_all ( p ) . unwrap ( ) ; } let db_ident = Ident :: new ( db_type . sqlx_type ( ) , Span :: call_site ( ) ) ; fs :: write ( module_path , quote ! { pub use sqlx_migrate prelude modules /// All the migrations. pub fn migrations ( ) impl IntoIterator Item Migration sqlx db_ident { migrations } } . to_string ( ) , ) . unwrap ( ) ; }
Generate Rust code from a migrations directory.
Generate Rust code from a migrations directory .
migrations_dir
impl AsRef<Path>
module_path
impl AsRef<Path>
db_type
DatabaseType
migrations_dir
impl AsRef<Path>
module_path
impl AsRef<Path>
db_type
DatabaseType
panics
This function is meant to be used in `build.rs` and will panic on errors.
This function is meant to be used in ` build . rs ` and will panic on errors .