-
Notifications
You must be signed in to change notification settings - Fork 146
Migration enums #312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Migration enums #312
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f67cb5a
generate EmbeddedMigrations enum
superstator e5a37d5
create enum from migration
superstator cb2de70
consolidate regex and remove lazy_static
superstator 8688f1c
fmt, cleanup
superstator 913cfa9
remove unused trait
superstator 7c22c39
use From for migration enum
superstator 576b1c6
remove unneeded usings
superstator 99eb306
Merge branch 'main' into enum_migrations
superstator cde45e4
add feature flag, update example project
superstator 61d76f0
Merge branch 'main' into enum_migrations
superstator 7adb6b9
fmt
superstator 1079c25
Merge branch 'main' into enum_migrations
superstator 542cf54
Update refinery_core/src/util.rs
superstator 42d0ac9
Update refinery_core/src/util.rs
superstator 6fc135f
Update refinery_core/src/util.rs
superstator 7101b6c
Update refinery_core/src/util.rs
superstator a788da9
Merge branch 'main' into enum_migrations
jxs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.