Skip to content

Commit 82170fc

Browse files
authored
Merge pull request #211 from Bootstrap-Academy/migrations
refactor(persistence): reorganize migrations
2 parents cb9ca9e + 1e56b04 commit 82170fc

File tree

38 files changed

+15
-17
lines changed

38 files changed

+15
-17
lines changed

.github/workflows/check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
- uses: actions/checkout@v4
5151
- uses: DeterminateSystems/nix-installer-action@main
5252
- run: |
53-
for m in academy_persistence/postgres/migrations/*.up.sql; do
53+
for m in academy_persistence/postgres/migrations/*/up.sql; do
5454
psql -h 127.0.0.1 academy academy < "$m"
5555
done
5656
- run: nix run --accept-flake-config .#scripts.generate-clorinde

academy_persistence/postgres/build.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,18 @@ fn emit_migrations(path: &Path) {
2929
}
3030

3131
fn collect_migrations() -> BTreeMap<String, (String, String)> {
32-
let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("migrations");
32+
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
33+
.join("migrations")
34+
.read_dir()
35+
.unwrap()
36+
.map(|file| {
37+
let file = file.unwrap();
38+
let name = file.file_name().into_string().unwrap();
3339

34-
let mut out = BTreeMap::new();
35-
for file in dir.read_dir().unwrap() {
36-
let file = file.unwrap();
37-
let name = file.file_name().into_string().unwrap();
40+
let up = std::fs::read_to_string(file.path().join("up.sql")).unwrap();
41+
let down = std::fs::read_to_string(file.path().join("down.sql")).unwrap();
3842

39-
if let Some(name) = name.strip_suffix(".up.sql").map(ToOwned::to_owned) {
40-
let (up, _) = out.entry(name).or_insert_with(Default::default);
41-
*up = std::fs::read_to_string(file.path()).unwrap();
42-
} else if let Some(name) = name.strip_suffix(".down.sql").map(ToOwned::to_owned) {
43-
let (_, down) = out.entry(name).or_insert_with(Default::default);
44-
*down = std::fs::read_to_string(file.path()).unwrap();
45-
}
46-
}
47-
out
43+
(name, (up, down))
44+
})
45+
.collect()
4846
}

0 commit comments

Comments
 (0)