The home for Hyperlane core contracts, sdk packages, and other infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hyperlane-monorepo/rust/agents/scraper/migration/bin/generate_entities.rs

114 lines
2.9 KiB

use std::path::Path;
use std::process::Stdio;
use std::time::Duration;
use tokio::fs::remove_dir_all;
use tokio::process::Command;
use tokio::time::sleep;
use common::*;
mod common;
const RAW_DB_PATH: &str = "./agents/scraper/src/db";
const DOCKER_NAME: &str = "scraper-entity-generator";
struct PostgresDockerContainer;
impl PostgresDockerContainer {
async fn start() -> Result<Self, ()> {
let status = Command::new("docker")
.args([
"run",
"--name",
DOCKER_NAME,
"-e",
"POSTGRES_PASSWORD=47221c18c610",
"-p",
"5432:5432",
"--rm",
"-d",
"postgres:14",
])
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status()
.await;
if let Ok(status) = status {
if status.success() {
Message Explorer Inbox Scraping (#1159) * Better hex processing * Cleanup clippy errors * Fix parsing of 160 bit values * Support multiple contracts with cursors * InboxIndexer for getting message processed events * Work on inbox indexing and delivered message linking * Use message hashes to link deliveries and also add hash indexes for common lookups * split up settings struct * Support scraper config for main fn * Multiple config parsing for scraper * Better docs and more reliant config loading * Refactoring building of contract items * Cut down on duplication * Support inbox indexer building * fmt * Scraper settings loading re-work * Fix errors, warnings, and cleanup * Fix clippy warnings * Fix hash index not supporting uniqueness * Fix after entity update * Remove special case * Better error messages for missing config values * Env prefix filtering * Improve error context for url without base error * Fix inbox domain bug * Actually I was wrong about domains, misinterpreted config * Fix loading settings method * Fix upsert error * Debugged and fixed incorrect txn linking with messages and deliveries * Cleanup * Update config for scraper * Update config for scraper * Delivered message linking; again. * Reduce call frequency of message linking query * Fixed typo * Fix init mistake * changed to agent_prefix * Domain settings * Use a loop * Add more docs * Remove semicolen * Increase linking frequency * Add moonbeam domain * Fmt * Renamed settings struct * Add docs * Add test for FROM_HEX_CHARS array
2 years ago
sleep(Duration::from_secs(2)).await;
return Ok(Self);
}
}
Err(())
}
}
impl Drop for PostgresDockerContainer {
fn drop(&mut self) {
let status = std::process::Command::new("docker")
.args(["stop", DOCKER_NAME])
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status();
if let Err(e) = status {
eprintln!("Encountered error when stopping postgres: {e}");
}
}
}
#[tokio::main]
async fn main() -> Result<(), DbErr> {
assert_eq!(
std::env::current_dir().unwrap().file_name().unwrap(),
"rust",
"Must run from the rust dir"
);
let postgres = PostgresDockerContainer::start();
let install_cli = tokio::spawn(
Command::new("cargo")
.args(["install", "sea-orm-cli"])
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status(),
);
let postgres = postgres.await.unwrap();
let db = init().await?;
Migrator::up(&db, None).await?;
drop(db);
let db_path = Path::new(RAW_DB_PATH);
if db_path.exists() {
remove_dir_all(db_path)
.await
.expect("Failed to delete old entity code");
}
assert!(install_cli.await.unwrap().unwrap().success());
let generate_status = Command::new("sea-orm-cli")
.env("DATABASE_URL", url())
.args([
"generate",
"entity",
"--output-dir",
db_path.to_str().unwrap(),
// we want expanded format because it plays nicely with the IDEs
"--expanded-format",
"--date-time-crate",
"time",
"--with-copy-enums",
])
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status()
.await
.expect("Failed to generate entities")
.success();
assert!(generate_status, "Failed to generate entities");
drop(postgres);
Ok(())
}