Jump to…
snowinitial commitqoxwzsukwmkx1mo
1//! Rebuild `df-db` whenever a migration changes.
2//!
3//! `sqlx::migrate!` embeds the contents of `migrations/` into the binary at
4//! **compile time**. Cargo cannot see that dependency by itself: nothing in
5//! `src/` mentions those files, so adding a migration does not make the crate
6//! look dirty and the old set stays embedded.
7//!
8//! That failure is silent and nasty. The binary starts, reports "migrations up
9//! to date", and then every query against a column the missing migration was
10//! supposed to add fails at runtime — which is exactly how it presented when it
11//! happened here: a `column r.search does not exist` from a build that thought
12//! it had applied migration 3.
13//!
14//! Emitting the directory as a dependency makes the whole thing ordinary again.
15
16fn main() {
17 // The directory itself, so an added or removed file is noticed…
18 println!("cargo:rerun-if-changed=../../migrations");
19
20 // …and each file, so an *edited* one is too. A directory's mtime does not
21 // change when a file inside it is modified in place.
22 if let Ok(entries) = std::fs::read_dir("../../migrations") {
23 for entry in entries.flatten() {
24 println!("cargo:rerun-if-changed={}", entry.path().display());
25 }
26 }
27}

27 lines · Rust