From 67b69f655fd8457cb3d43100b1fa99244970c64f Mon Sep 17 00:00:00 2001 From: Mark Sinclair Date: Wed, 12 Nov 2025 15:18:37 +0000 Subject: [PATCH] add check for manual migration sync that will fail on `cargo build` in CI --- Cargo.lock | 1 + Cargo.toml | 1 + nym-data-observatory/Cargo.toml | 1 + nym-data-observatory/build.rs | 53 ++++++++++++++++++++++++++++++++- 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 19376eb2b8..e60ae9c5de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5717,6 +5717,7 @@ dependencies = [ "chrono", "clap", "cosmrs", + "glob", "nym-bin-common", "nym-config", "nym-network-defaults", diff --git a/Cargo.toml b/Cargo.toml index 28f7f6c319..85e43d76e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -266,6 +266,7 @@ futures = "0.3.31" futures-util = "0.3" generic-array = "0.14.7" getrandom = "0.2.10" +glob = "0.3" handlebars = "3.5.5" hex = "0.4.3" hickory-resolver = "0.25" diff --git a/nym-data-observatory/Cargo.toml b/nym-data-observatory/Cargo.toml index 9f4dfd225a..8ecbe74e0a 100644 --- a/nym-data-observatory/Cargo.toml +++ b/nym-data-observatory/Cargo.toml @@ -46,5 +46,6 @@ utoipauto = { workspace = true } [build-dependencies] anyhow = { workspace = true } +glob = { workspace = true } tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } sqlx = { workspace = true, features = ["runtime-tokio-rustls", "postgres"] } \ No newline at end of file diff --git a/nym-data-observatory/build.rs b/nym-data-observatory/build.rs index c1dcd9dcb3..6b2122d748 100644 --- a/nym-data-observatory/build.rs +++ b/nym-data-observatory/build.rs @@ -1,8 +1,59 @@ // Copyright 2025 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 +use glob::glob; +use std::env; +use std::path::Path; -fn main() { +fn main() -> anyhow::Result<()> { + // check if migrations in "../common/nyxd-scraper-psql/sql_migrations/* are in "nym-data-observatory/migrations" + println!("Checking common migrations..."); + let manifest_dir_string = env::var("CARGO_MANIFEST_DIR").unwrap(); + let common_migrations_path = Path::new(&manifest_dir_string) + .join("../common/nyxd-scraper-psql/sql_migrations/") + .canonicalize()?; + let output_path = Path::new(&manifest_dir_string) + .join("migrations") + .canonicalize()?; + println!( + "output_path: {:?} (exists = {})", + output_path, + output_path.exists() + ); + let common_migrations_path = common_migrations_path.as_path(); + println!( + "common_migrations_path: {:?} (exists = {})", + common_migrations_path, + common_migrations_path.exists() + ); + for file in glob(&format!("{}/*", common_migrations_path.to_str().unwrap())) + .unwrap() + .flatten() + { + println!("- checking if {file:?} exists in nym-data-observatory/migrations directory..."); + let filename = file + .as_path() + .file_name() + .expect("migration filename is found"); + let filename = output_path.join(filename); + println!( + "- {} {file:?} => {filename:?} (exists = {})", + if filename.exists() { "✅" } else { "❌" }, + filename.exists() + ); + + if !filename.exists() { + anyhow::bail!( + "migration {file:?} does not exist in nym-data-observatory/migrations directory, please check and copy it" + ); + } + } + + // sqlx if let Ok(database_url) = std::env::var("DATABASE_URL") { println!("cargo:rustc-env=DATABASE_URL={database_url}"); } + + println!("✅ done"); + + Ok(()) }