// Copyright 2023 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 use anyhow::Context; #[tokio::main] async fn main() -> anyhow::Result<()> { use sqlx::{Connection, SqliteConnection}; use std::env; let out_dir = env::var("OUT_DIR")?; let database_path = format!("{out_dir}/scraper-example.sqlite"); // remove the db file if it already existed from previous build // in case it was from a different branch if std::fs::exists(&database_path)? { std::fs::remove_file(&database_path)?; } let mut conn = SqliteConnection::connect(&format!("sqlite://{database_path}?mode=rwc")) .await .context("Failed to create SQLx database connection")?; sqlx::migrate!("./sql_migrations") .run(&mut conn) .await .context("Failed to perform SQLx migrations")?; #[cfg(target_family = "unix")] println!("cargo:rustc-env=DATABASE_URL=sqlite://{}", &database_path); #[cfg(target_family = "windows")] // for some strange reason we need to add a leading `/` to the windows path even though it's // not a valid windows path... but hey, it works... println!("cargo:rustc-env=DATABASE_URL=sqlite:///{}", &database_path); Ok(()) }