-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* generate EmbeddedMigrations enum * create enum from migration * consolidate regex and remove lazy_static * fmt, cleanup * remove unused trait * use From for migration enum * remove unneeded usings * add feature flag, update example project * fmt * Update refinery_core/src/util.rs Co-authored-by: João Oliveira <[email protected]> * Update refinery_core/src/util.rs Co-authored-by: João Oliveira <[email protected]> * Update refinery_core/src/util.rs Co-authored-by: João Oliveira <[email protected]> * Update refinery_core/src/util.rs Co-authored-by: João Oliveira <[email protected]> --------- Co-authored-by: João Oliveira <[email protected]>
- Loading branch information
1 parent
9672719
commit 135acc8
Showing
11 changed files
with
183 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ members = [ | |
"refinery", | ||
"refinery_cli", | ||
"refinery_core", | ||
"refinery_macros" | ||
"refinery_macros", | ||
"examples" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "refinery-examples" | ||
version = "0.8.12" | ||
authors = ["Katharina Fey <[email protected]>", "João Oliveira <[email protected]>"] | ||
description = "Minimal Refinery usage example" | ||
license = "MIT OR Apache-2.0" | ||
documentation = "https://docs.rs/refinery/" | ||
repository = "https://github.com/rust-db/refinery" | ||
edition = "2021" | ||
|
||
[features] | ||
enums = ["refinery/enums"] | ||
|
||
[dependencies] | ||
refinery = { path = "../refinery", features = ["rusqlite"] } | ||
rusqlite = "0.29" | ||
barrel = { version = "0.7", features = ["sqlite3"] } | ||
log = "0.4" | ||
env_logger = "0.11" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use barrel::backend::Sqlite as Sql; | ||
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), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters