-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
The embed_migrations!
macro doesn't pick up new migration files due to cargo build cache
#3119
Comments
Thanks for opening this bug report. Can you check if the same thing happens with the implementation on the master branch? The |
Thanks @weiznich for the swift reply. I was able to reproduce the issue on the master branch. I had to update my main.rs slightly: use diesel::{pg::PgConnection, prelude::*};
use diesel_migrations::EmbeddedMigrations;
use diesel_migrations::{embed_migrations, MigrationHarness};
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("./migrations");
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut conn = PgConnection::establish("postgres://postgres@localhost:1234/test")?;
println!("Migrating...");
conn.run_pending_migrations(MIGRATIONS).unwrap();
Ok(())
} The issue is the same as documented before: cargo does not see the new SQL migration scripts, and reuses the outdated binary. As a result, the latest migration scripts are missing from the binary. |
The issue shows up here: https://github.com/diesel-rs/diesel/blob/master/diesel_migrations/migrations_internals/src/lib.rs#L89 cargo doesn't have the same level of integration with |
Fixing this requires the stabilization of |
launchbadge/sqlx#1332 might be relevant to see how others fixing a similar issue. |
`embed_migrations!` (Addresses diesel-rs#3119)
`embed_migrations!` (Addresses diesel-rs#3119)
Setup
Versions
Problem Description
I use the
embed_migrations!
to generate a binary to run Diesel migrations. Cargo will sometimes reuse the previously built binary instead of building a new one, because it didn't realize its cache became invalid. This happens when I'm only adding new files to themigrations
directory.What are you trying to accomplish?
Build a binary to run the Diesel migrations.
What is the expected output?
The binary produced by
cargo build
should run all of the migration files, including the most recent ones.What is the actual output?
Cargo didn't rebuild the crate, and the binary is now outdated. As a result, if I run the binary, recent migrations will be missing.
Are you seeing any additional errors?
No
Steps to reproduce
/src/bin/run-migrations.rs
:cargo build
cargo build
again, and observe that cargo skipped the build.The resulting binary misses the additional SQL migration.
Checklist
closed if this is not the case)
Workaround
It is possible to invalidate the build cache with a
/build.rs
file:The text was updated successfully, but these errors were encountered: