Comments (8)
Interesting, can you disclose you usecase for this? And why comparing the name would not be enough?
Thanks!
from refinery.
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 i32
instead of a string which would be more efficient and much less error prone.
from refinery.
The idea seems interesting, but if it's a TryInto
it means there's still going to be a runtime check, which I assume is converting the migration name from string into the matching enum right?
from refinery.
My thought was to have the macro output a TryInto
impl that maps migration.version
to the enum discriminant, so no runtime string comparisons. That way the only failure mode for TryInto
would be somehow instantiating a Migration
struct with an invalid version number, and I think the only obvious way for that to happen would be to monkey with the schema history table or delete applied migrations.
from refinery.
then I'd say it can be an Into
right?
from refinery.
It would have to panic on a bad migration version but otherwise sure
from refinery.
and isn't that most probably unreachable!
?
from refinery.
Off the top of my head the obvious way to get there (short of unsafe
) would be to have two sets of embedded migrations for two databases, and then try to convert one into the wrapping enum for the other. I'm fine with that being a panic if you are, and it would eliminate the need to make changes in error.rs
.
from refinery.
Related Issues (20)
- mysql_async, no default features HOT 2
- Broken docker image 0.8.11 HOT 2
- Support mysql 24.0.0 HOT 3
- Support SurrealDB HOT 1
- Update broken Flyway documentation link HOT 1
- Support a function similar to flyway baseline HOT 1
- Get final database schema after all migrations are run HOT 3
- Current rusqlite version (0.30.0) not supported? HOT 1
- serde properties of Config should be under a feature gate along with Toml serde impl HOT 2
- New Files are not Detected by embed_migrations HOT 2
- Sqlx no longer supported because Migrate no longer implemented by Config HOT 3
- refinery_cli: ERROR: cannot insert multiple commands into a prepared statement HOT 7
- Add support for rusqlite 0.31.0 HOT 4
- refinery_cli: Error: `error applying update`, `db error: ERROR: relation "refinery_schema_history" does not exist` HOT 5
- Unreproducible release for refinery-core 0.8.13 HOT 2
- Changelog lists release 0.8.14 twice HOT 1
- Add run_iter_async HOT 2
- Build error with tiberius without serde HOT 2
- Allow specifying database schema on migrations (MSSQL database) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from refinery.