You've already forked AstralRinth
forked from didirus/AstralRinth
Support alternative read-replica PgPool (#4374)
* Add ReadOnlyPgPool * Clippy, fmt
This commit is contained in:
committed by
GitHub
parent
67e090565e
commit
3fc55184a7
@@ -1,4 +1,6 @@
|
||||
use labrinth::{database::redis::RedisPool, search};
|
||||
use labrinth::database::ReadOnlyPgPool;
|
||||
use labrinth::database::redis::RedisPool;
|
||||
use labrinth::search;
|
||||
use sqlx::{PgPool, postgres::PgPoolOptions};
|
||||
use std::time::Duration;
|
||||
use url::Url;
|
||||
@@ -36,6 +38,7 @@ const TEMPLATE_DATABASE_NAME: &str = "labrinth_tests_template";
|
||||
#[derive(Clone)]
|
||||
pub struct TemporaryDatabase {
|
||||
pub pool: PgPool,
|
||||
pub ro_pool: ReadOnlyPgPool,
|
||||
pub redis_pool: RedisPool,
|
||||
pub search_config: labrinth::search::SearchConfig,
|
||||
pub database_name: String,
|
||||
@@ -74,6 +77,8 @@ impl TemporaryDatabase {
|
||||
.await
|
||||
.expect("Connection to temporary database failed");
|
||||
|
||||
let ro_pool = ReadOnlyPgPool::from(pool.clone());
|
||||
|
||||
println!("Running migrations on temporary database");
|
||||
|
||||
// Performs migrations
|
||||
@@ -90,6 +95,7 @@ impl TemporaryDatabase {
|
||||
search::SearchConfig::new(Some(temp_database_name.clone()));
|
||||
Self {
|
||||
pool,
|
||||
ro_pool,
|
||||
database_name: temp_database_name,
|
||||
redis_pool,
|
||||
search_config,
|
||||
@@ -184,6 +190,7 @@ impl TemporaryDatabase {
|
||||
let name = generate_random_name("test_template_");
|
||||
let db = TemporaryDatabase {
|
||||
pool: pool.clone(),
|
||||
ro_pool: ReadOnlyPgPool::from(pool.clone()),
|
||||
database_name: TEMPLATE_DATABASE_NAME.to_string(),
|
||||
redis_pool: RedisPool::new(Some(name.clone())),
|
||||
search_config: search::SearchConfig::new(Some(name)),
|
||||
|
||||
@@ -26,6 +26,7 @@ pub async fn setup(db: &database::TemporaryDatabase) -> LabrinthConfig {
|
||||
}
|
||||
|
||||
let pool = db.pool.clone();
|
||||
let ro_pool = db.ro_pool.clone();
|
||||
let redis_pool = db.redis_pool.clone();
|
||||
let search_config = db.search_config.clone();
|
||||
let file_host: Arc<dyn file_hosting::FileHost + Send + Sync> =
|
||||
@@ -40,6 +41,7 @@ pub async fn setup(db: &database::TemporaryDatabase) -> LabrinthConfig {
|
||||
|
||||
labrinth::app_setup(
|
||||
pool.clone(),
|
||||
ro_pool.clone(),
|
||||
redis_pool.clone(),
|
||||
search_config,
|
||||
&mut clickhouse,
|
||||
|
||||
Reference in New Issue
Block a user