Skip to content
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

New Files are not Detected by embed_migrations #309

Open
cole-abbeduto-particle opened this issue Jan 26, 2024 · 2 comments
Open

New Files are not Detected by embed_migrations #309

cole-abbeduto-particle opened this issue Jan 26, 2024 · 2 comments

Comments

@cole-abbeduto-particle
Copy link

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
Copy link
Author

cole-abbeduto-particle commented Jan 26, 2024

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

@jxs
Copy link
Member

jxs commented Feb 14, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants