refactor: drop postgres leftovers, narrow bootstrap api
This commit is contained in:
@@ -44,7 +44,7 @@ use application::wrapup::deps::{
|
||||
};
|
||||
use domain::value_objects::InstanceIdentity;
|
||||
|
||||
use crate::{DatabaseOutput, Repositories};
|
||||
use crate::{Repositories, database::DatabaseOutput};
|
||||
|
||||
/// The composition root's single assembly point: every one of the server-facing
|
||||
/// deps structs, built once from the already-constructed `Repositories` and
|
||||
|
||||
@@ -2,16 +2,11 @@ use std::sync::Arc;
|
||||
|
||||
use anyhow::Context;
|
||||
use domain::ports::{
|
||||
AuthService, ImageRefCommand, ImageRefQuery, LocalApContentQuery, MetadataClient,
|
||||
MovieDeduplicator, ObjectStorage, PasswordHasher, PosterFetcherClient,
|
||||
RefreshSessionRepository, UserProfileFieldsRepository, WatchEventCommand, WatchEventQuery,
|
||||
WebhookTokenRepository,
|
||||
AuthService, ImageRefCommand, ImageRefQuery, MetadataClient, MovieDeduplicator, ObjectStorage,
|
||||
PasswordHasher, PosterFetcherClient, RefreshSessionRepository, UserProfileFieldsRepository,
|
||||
WatchEventCommand, WatchEventQuery, WebhookTokenRepository,
|
||||
};
|
||||
|
||||
pub enum DbPool {
|
||||
Sqlite(sqlx::SqlitePool),
|
||||
}
|
||||
|
||||
pub struct DatabaseOutput {
|
||||
pub movie_command: Arc<dyn domain::ports::MovieCommand>,
|
||||
pub movie_query: Arc<dyn domain::ports::MovieQuery>,
|
||||
@@ -31,13 +26,15 @@ pub struct DatabaseOutput {
|
||||
pub search_port: Arc<dyn domain::ports::SearchPort>,
|
||||
pub search_command: Arc<dyn domain::ports::SearchCommand>,
|
||||
pub profile_fields: Arc<dyn UserProfileFieldsRepository>,
|
||||
pub ap_content: Arc<dyn LocalApContentQuery>,
|
||||
#[cfg(feature = "federation")]
|
||||
pub ap_content: Arc<dyn domain::ports::LocalApContentQuery>,
|
||||
pub wrapup_stats: Arc<dyn domain::ports::WrapUpStatsQuery>,
|
||||
pub wrapup_repo: Arc<dyn domain::ports::WrapUpRepository>,
|
||||
pub insights: Arc<dyn domain::ports::InsightsQuery>,
|
||||
pub goal_command: Arc<dyn domain::ports::GoalCommand>,
|
||||
pub goal_query: Arc<dyn domain::ports::GoalQuery>,
|
||||
pub user_settings: Arc<dyn domain::ports::UserSettingsRepository>,
|
||||
#[cfg(feature = "federation")]
|
||||
pub federation_settings: std::sync::Arc<dyn domain::ports::UserFederationSettingsQuery>,
|
||||
pub remote_goal: Arc<dyn domain::ports::RemoteGoalRepository>,
|
||||
pub refresh_session: Arc<dyn RefreshSessionRepository>,
|
||||
@@ -46,7 +43,7 @@ pub struct DatabaseOutput {
|
||||
pub image_ref_query: Arc<dyn ImageRefQuery>,
|
||||
pub follow_command: Arc<dyn domain::ports::FollowCommand>,
|
||||
pub follow_query: Arc<dyn domain::ports::FollowQuery>,
|
||||
pub db_pool: DbPool,
|
||||
pub db_pool: sqlx::SqlitePool,
|
||||
}
|
||||
|
||||
pub async fn build_database_adapters(
|
||||
@@ -105,6 +102,7 @@ fn assemble(
|
||||
search_port: sp,
|
||||
search_command: sc,
|
||||
profile_fields: pf,
|
||||
#[cfg(feature = "federation")]
|
||||
ap_content: w.ap_content,
|
||||
wrapup_stats: w.wrapup_stats,
|
||||
wrapup_repo: w.wrapup_repo,
|
||||
@@ -112,6 +110,7 @@ fn assemble(
|
||||
goal_command: w.goal_command,
|
||||
goal_query: w.goal_query,
|
||||
user_settings: w.user_settings,
|
||||
#[cfg(feature = "federation")]
|
||||
federation_settings: w.federation_settings,
|
||||
remote_goal: w.remote_goal,
|
||||
refresh_session: Arc::new(sqlite::SqliteRefreshSessionAdapter::new(w.pool.clone())) as _,
|
||||
@@ -120,7 +119,7 @@ fn assemble(
|
||||
image_ref_query,
|
||||
follow_command: Arc::clone(&social) as _,
|
||||
follow_query: social as _,
|
||||
db_pool: DbPool::Sqlite(w.pool),
|
||||
db_pool: w.pool,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -148,14 +147,6 @@ pub fn build_object_storage(
|
||||
object_storage::create(config)
|
||||
}
|
||||
|
||||
pub fn build_profile_fields_repo(
|
||||
pool: &DbPool,
|
||||
) -> anyhow::Result<Arc<dyn UserProfileFieldsRepository>> {
|
||||
match pool {
|
||||
DbPool::Sqlite(pool) => Ok(sqlite::create_profile_fields_repo(pool.clone())),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn warn_if_database_backend_set() {
|
||||
if let Ok(v) = std::env::var("DATABASE_BACKEND")
|
||||
&& v != "sqlite"
|
||||
|
||||
@@ -4,8 +4,6 @@ use std::sync::Arc;
|
||||
use anyhow::Context;
|
||||
use domain::ports::{EventConsumer, EventPublisher};
|
||||
|
||||
use crate::database::DbPool;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum EventBusBackend {
|
||||
Db,
|
||||
@@ -29,17 +27,13 @@ impl EventBusBackend {
|
||||
}
|
||||
|
||||
pub async fn create_publisher(
|
||||
db_pool: &DbPool,
|
||||
db_pool: &sqlx::SqlitePool,
|
||||
config: &config::AppConfig,
|
||||
) -> anyhow::Result<Arc<dyn EventPublisher>> {
|
||||
match EventBusBackend::from_config(&config.events)? {
|
||||
EventBusBackend::Db => {
|
||||
tracing::info!("event bus: DB queue");
|
||||
Ok(match db_pool {
|
||||
DbPool::Sqlite(pool) => {
|
||||
sqlite::SqliteEventQueue::create_publisher(pool.clone(), &config.events).await?
|
||||
}
|
||||
})
|
||||
Ok(sqlite::SqliteEventQueue::create_publisher(db_pool.clone(), &config.events).await?)
|
||||
}
|
||||
#[cfg(feature = "nats")]
|
||||
EventBusBackend::Nats => {
|
||||
@@ -52,19 +46,13 @@ pub async fn create_publisher(
|
||||
}
|
||||
|
||||
pub async fn create_channel(
|
||||
db_pool: &DbPool,
|
||||
db_pool: &sqlx::SqlitePool,
|
||||
config: &config::AppConfig,
|
||||
) -> anyhow::Result<(Arc<dyn EventPublisher>, Arc<dyn EventConsumer>)> {
|
||||
match EventBusBackend::from_config(&config.events)? {
|
||||
EventBusBackend::Db => {
|
||||
tracing::info!("event bus: DB queue");
|
||||
match db_pool {
|
||||
DbPool::Sqlite(pool) => Ok(sqlite::SqliteEventQueue::create_channel(
|
||||
pool.clone(),
|
||||
&config.events,
|
||||
)
|
||||
.await?),
|
||||
}
|
||||
Ok(sqlite::SqliteEventQueue::create_channel(db_pool.clone(), &config.events).await?)
|
||||
}
|
||||
#[cfg(feature = "nats")]
|
||||
EventBusBackend::Nats => {
|
||||
|
||||
@@ -64,8 +64,7 @@ pub async fn wire_server_social(
|
||||
config: &config::AppConfig,
|
||||
event_publisher: &Arc<dyn EventPublisher>,
|
||||
) -> anyhow::Result<ServerSocial> {
|
||||
let crate::database::DbPool::Sqlite(pool) = &db.db_pool;
|
||||
let fed_repos = sqlite_federation::wire(pool.clone(), instance.clone());
|
||||
let fed_repos = sqlite_federation::wire(db.db_pool.clone(), instance.clone());
|
||||
|
||||
let ap = activitypub::wire(activitypub::ActivityPubDeps {
|
||||
activity_repo: fed_repos.activity,
|
||||
@@ -117,7 +116,7 @@ pub async fn wire_server_social(
|
||||
remote_watchlist: fed_repos.remote_watchlist,
|
||||
federation_admin: fed_repos.admin_query,
|
||||
federated_profile: Some(sqlite::create_federated_profile_query(
|
||||
pool.clone(),
|
||||
db.db_pool.clone(),
|
||||
instance.clone(),
|
||||
)),
|
||||
})
|
||||
@@ -132,8 +131,7 @@ pub async fn wire_worker_handlers(
|
||||
config: &config::AppConfig,
|
||||
event_publisher: &Arc<dyn EventPublisher>,
|
||||
) -> anyhow::Result<Vec<Arc<dyn domain::ports::EventHandler>>> {
|
||||
let crate::database::DbPool::Sqlite(pool) = &db.db_pool;
|
||||
let fed_repos = sqlite_federation::wire(pool.clone(), instance.clone());
|
||||
let fed_repos = sqlite_federation::wire(db.db_pool.clone(), instance.clone());
|
||||
|
||||
let ap_wire = activitypub::wire(activitypub::ActivityPubDeps {
|
||||
activity_repo: fed_repos.activity,
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
//! [`build_worker`]; everything between configuration and a running service is
|
||||
//! assembled here (ADR-0005, ADR-0013).
|
||||
|
||||
pub mod build;
|
||||
pub mod database;
|
||||
mod build;
|
||||
mod database;
|
||||
mod event_bus;
|
||||
mod federation;
|
||||
#[cfg(feature = "federation")]
|
||||
@@ -15,9 +15,7 @@ mod server;
|
||||
mod tracing_setup;
|
||||
mod worker;
|
||||
|
||||
pub use build::{build_deps, build_worker_deps};
|
||||
pub use database::{DatabaseOutput, DbPool};
|
||||
pub use event_bus::EventBusBackend;
|
||||
pub use build::build_deps;
|
||||
pub use repositories::Repositories;
|
||||
pub use server::{ServerApp, build_server, build_server_on};
|
||||
pub use tracing_setup::init_tracing;
|
||||
|
||||
@@ -66,7 +66,7 @@ async fn assemble(
|
||||
event_publisher: Arc::clone(&event_publisher_arc),
|
||||
person_enrichment,
|
||||
};
|
||||
let worker_deps = crate::build_worker_deps(&db, &worker_services);
|
||||
let worker_deps = crate::build::build_worker_deps(&db, &worker_services);
|
||||
|
||||
let image_ref_command = Arc::clone(&db.image_ref_command);
|
||||
let image_ref_query = Arc::clone(&db.image_ref_query);
|
||||
|
||||
Reference in New Issue
Block a user