-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathmain.rs
41 lines (34 loc) · 1.2 KB
/
main.rs
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
use log::info;
use refinery::Migration;
use rusqlite::Connection;
refinery::embed_migrations!("migrations");
fn main() {
env_logger::init();
let mut conn = Connection::open_in_memory().unwrap();
let use_iteration = std::env::args().any(|a| a.to_lowercase().eq("--iterate"));
if use_iteration {
// create an iterator over migrations as they run
for migration in migrations::runner().run_iter(&mut conn) {
process_migration(migration.expect("Migration failed!"));
}
} else {
// or run all migrations in one go
migrations::runner().run(&mut conn).unwrap();
}
}
fn process_migration(migration: Migration) {
#[cfg(not(feature = "enums"))]
{
// run something after each migration
info!("Post-processing a migration: {}", migration)
}
#[cfg(feature = "enums")]
{
// or with the `enums` feature enabled, match against migrations to run specific post-migration steps
use migrations::EmbeddedMigration;
match migration.into() {
EmbeddedMigration::Initial(m) => info!("V{}: Initialized the database!", m.version()),
m => info!("Got a migration: {:?}", m),
}
}
}