-
Notifications
You must be signed in to change notification settings - Fork 126
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
Wrap embedded migrations with enums #303
Comments
Interesting, can you disclose you usecase for this? And why comparing the name would not be enough? |
Sure, it's just an extension of the usecase for iteration. For example, if my app stores metadata in sqlite but also stores complex binary data on disk, I might need to initialize a directory structure after the initial migration, and then reshuffle a bunch of files during a later migration. fn main() -> Result<(), Error> {
let mut conn = Connection::open("test.db").unwrap();
for migration in embedded::migrations::runner().run_iter(&mut conn) {
match migration?.try_into()? {
EmbeddedMigration::Initial(_) => init_filesystem(),
EmbeddedMigration::AddCarsAndMotosTable(_) => migrate_v2(),
_ => ()
}
}
Ok(())
}
fn init_filesystem() -> Result<(), Error> {
// create fs junk
Ok(())
}
fn migrate_v2() -> Result<(), Error> {
// update fs junk folowing db changes
Ok(())
} I can absolutely achieve this just matching names, but enums would allow for compile-time checking. My thought was to use the migration version as the enum discriminant so strictly speaking I'd be matching an |
The idea seems interesting, but if it's a |
My thought was to have the macro output a |
then I'd say it can be an |
It would have to panic on a bad migration version but otherwise sure |
and isn't that most probably |
Off the top of my head the obvious way to get there (short of |
Now that I have a way to iterate over migrations as I run them, I'd like to be able to match strongly against them. Something like:
I think this could be done without any changes to
Migration
orRunner
, but just by emitting an enum andimpl TryFrom<Migration>
withembed_migrations!
. Is this something you'd be open to another PR for?The text was updated successfully, but these errors were encountered: