From 63d7827dd1a3d4831fc7dfce8f14412cb531e215 Mon Sep 17 00:00:00 2001 From: Lan Lou Date: Wed, 6 Nov 2024 20:14:29 -0500 Subject: [PATCH] Make database_url configurable and remove migrate_test --- optd-persistent/src/bin/migrate_test.rs | 16 ---------------- optd-persistent/src/lib.rs | 6 ++---- 2 files changed, 2 insertions(+), 20 deletions(-) delete mode 100644 optd-persistent/src/bin/migrate_test.rs diff --git a/optd-persistent/src/bin/migrate_test.rs b/optd-persistent/src/bin/migrate_test.rs deleted file mode 100644 index 65f3b74..0000000 --- a/optd-persistent/src/bin/migrate_test.rs +++ /dev/null @@ -1,16 +0,0 @@ -use optd_persistent::{migrate, TEST_DATABASE_FILE, TEST_DATABASE_URL}; -use sea_orm::*; -use sea_orm_migration::prelude::*; - -#[tokio::main] -async fn main() { - let _ = std::fs::remove_file(TEST_DATABASE_FILE); - - let db = Database::connect(TEST_DATABASE_URL) - .await - .expect("Unable to connect to the database"); - - migrate(&db) - .await - .expect("Something went wrong during migration"); -} diff --git a/optd-persistent/src/lib.rs b/optd-persistent/src/lib.rs index 9510e5c..cbee871 100644 --- a/optd-persistent/src/lib.rs +++ b/optd-persistent/src/lib.rs @@ -45,9 +45,9 @@ pub struct BackendManager { impl BackendManager { /// Creates a new `BackendManager`. - pub async fn new() -> StorageResult { + pub async fn new(database_url: Option<&str>) -> StorageResult { Ok(Self { - db: Database::connect(DATABASE_URL).await?, + db: Database::connect(database_url.unwrap_or(DATABASE_URL)).await?, latest_epoch_id: AtomicUsize::new(0), }) } @@ -55,8 +55,6 @@ impl BackendManager { pub const DATABASE_URL: &str = "sqlite:./sqlite.db?mode=rwc"; pub const DATABASE_FILE: &str = "./sqlite.db"; -pub const TEST_DATABASE_URL: &str = "sqlite:./test.db?mode=rwc"; -pub const TEST_DATABASE_FILE: &str = "./test.db"; pub async fn migrate(db: &DatabaseConnection) -> Result<(), DbErr> { Migrator::refresh(db).await