refinery icon indicating copy to clipboard operation
refinery copied to clipboard

New Files are not Detected by embed_migrations

Open cole-abbeduto-particle opened this issue 1 year ago • 4 comments
trafficstars

Hello folks,

We've been using refinery for a while now and have noticed that it never seems to pick up new files unless we explicitly force a rebuild of the migration binary we use by changing a line in it for example.

I've tested this a few different ways and I do want to say that it does seem to pick up on existing file changes and deletes of files it knows about, but it never picks up on adding new files without forcing a rebuild of the binary

Should be able to minimally reproduce with a quick log of the migrations it knows about

mod embedded {
    use refinery::embed_migrations;
    embed_migrations!("../sql");
}

fn main() {
    let runner = embedded::migrations::runner();
    let mut migs = runner.get_migrations().clone();
    migs.sort_by_key(|m| m.version());
    let files = migs.iter().map(|mig| {
        format!("{}: {}", mig.version(), mig.name())
    }).collect::<Vec<_>>();
    println!("Migrations: {:#?}", files);
}

Throwing this in a project with refinery and running it the first time it should properly pick up on all files in the sql folder. However, when I you add a new folder and re-run the binary without touching the other files in the sql folder, touching the src/main.rs, or anything else that would cause an explicit rebuild will show that it doesn't seem to pick up on the new files.

Is there something we are doing obviously wrong here? Does anybody else run into this (we hit in CI constantly and it's causing problems)? Is there a change that could be made to our usage or to the project that would fix this behavior? If not, it could be useful to add a warning in the main README or on docs.rs somewhere.

cole-abbeduto-particle avatar Jan 26 '24 05:01 cole-abbeduto-particle

After investigating build scripts, adding a quick build.rs with a rerun-if-changed was a good temp fix for us.

fn main() {
    println!("cargo:rerun-if-changed=../sql");
}

But still not sure why refinery isn't able to pick up adding files itself

cole-abbeduto-particle avatar Jan 26 '24 06:01 cole-abbeduto-particle

Hi, and thanks for the the interest! Yeah with sql migrations makes sense as there isn't a way for the rust compiler to detect those files as they aren't part of the project, thanks for posting a resolution to the problem!

Update: would you be interested in updating the README.md with this tip for sql migrations?

jxs avatar Feb 14 '24 15:02 jxs