Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upMove migration API from the diesel-cli crate into another diesel crate #1591
Comments
This comment has been minimized.
vityafx
commented
Mar 9, 2018
This comment has been minimized.
|
For what it's worth, I ran into the same problem while trying to build an app, and embedded migrations turned out to be an adequate solution for me. Here's my code in case it's helpful: // Migrations get pulled into the final binary. This makes it quite a bit
// easier to run them on remote clusters without trouble.
embed_migrations!("./migrations");
...
fn subcommand_migrate(log: &Logger, matches: &ArgMatches, options: &GlobalOptions) -> Result<()> {
let _matches = matches.subcommand_matches("migration").unwrap();
let conn = connection(log)?;
info!(log, "Running migrations");
if options.quiet {
embedded_migrations::run(&*conn)
} else {
embedded_migrations::run_with_output(&*conn, &mut std::io::stdout())
}.chain_err(|| "Error running migrations")?;
info!(log, "Finished migrations");
Ok(())
}It has an advantage compared to containerizing The downside is that down migrations, or any kind of finer migration operations (rolling back/forward by steps or anything else) aren't supported. This is usually fine given that my migrations are well-vetted before going to prod and in case of an emergency I still have a |
This comment has been minimized.
vityafx
commented
Mar 9, 2018
•
|
@brandur Yes, I am already trying this right now. But I am gonna perform migrations silently, without needing for explicit command call, so you just run the app in the docker image and the database is set up. Thanks for your response, now I am sure this is it. This issue would not be created if the diesel had all of this great stuff documented. The project is so big and is so complex. A lot of time I just have to go to this repository and try searching in the code. |
vityafx
closed this
Mar 9, 2018
This comment has been minimized.
You did literally link to the documentation for it one comment ago. ;) |
This comment has been minimized.
vityafx
commented
Mar 10, 2018
•
|
@brandur How do you compile it in the
Or, hm, you dont.. Interesting thing:
@sgrif Yes, but before that I had to read a part of source code. This crate was not mentioned on the https://diesel.rs or diesel docs. |
This comment has been minimized.
|
@vityafx Mine seems to work well. Maybe make sure that you follow all the caveats in the project's README. For example, it's suggested that this be added to [dependencies]
# This is needed to make sure that Cargo statically links against
# `libssl`. This should happen automatically, but it doesn't.
openssl-sys = "0.9"
[patch.crates-io]
# This is needed to handle cross-compilation of libpq.
pq-sys = { git = 'https://github.com/golddranks/pq-sys' }If it helps, here's my completed
@sgrif I'm going to second that although it's really nice that some of this documentation does turn out to exist, it's not very discoverable. I almost always find things by |
This comment has been minimized.
vityafx
commented
Mar 10, 2018
|
@brandur I have done that already without success. |
This comment has been minimized.
|
@vityafx Based on your compilation error, it seems that somehow OpenSSL might be absent from the image or something. Unfortunately I'm cargo culting to a large degree myself and not really an expert, but if you're really stuck, I'd suggest going back to the beginning and trying to get it configured again from scratch. If you'd like, you can use by |
This comment has been minimized.
vityafx
commented
Mar 10, 2018
|
@brandur I have doubly checked that the library is there and it contains the needed symbol. I am stuck because everything seems to be okay but it is not. Thanks for the help anyway. |
vityafx commentedMar 9, 2018
•
edited
I am packaging my app into a docker image. So, it is packaged but I must perform migrations for making it working correctly. I have to use the
diesel-clibinary crate but the docker image with it is 1.5GB in size. It is really wasteful because I need 1.5GB only for performing one single command (ofdiesel-cli). Everyone would prefer a singlediesel-clidocker image but it is impossible to create it at this moment (it can't be compiled with musl yet). The other option and actually the one which is better - move out the migration-related code from thediesel-cliinto separate crate, so the rust application can depend on it and call the function right in the beginning of itsmainfunction. After that thediesel-clicrate could depend on that newdiesel-XXXcrate and simply call its functions.