refactor: drop postgres backend

This commit is contained in:
2026-10-25 20:34:07 +01:00
parent 59238a36d8
commit 933400e1c2
82 changed files with 77 additions and 7937 deletions

View File

@@ -8,7 +8,6 @@ license = "MIT"
[features]
default = ["sqlite", "sqlite-federation"]
sqlite = ["dep:sqlite", "dep:sqlite-event-queue", "dep:sqlite-search", "infra-wiring/sqlite", "composition/sqlite"]
postgres = ["dep:postgres", "dep:postgres-event-queue", "dep:postgres-search", "infra-wiring/postgres", "composition/postgres"]
nats = ["dep:nats", "infra-wiring/nats", "composition/nats"]
# Meta-feature: true when any federation adapter is active — keeps all #[cfg(feature = "federation")] gates working
federation = ["application/federation", "presentation/federation"]
@@ -20,14 +19,6 @@ sqlite-federation = [
"federation",
"composition/sqlite-federation",
]
postgres-federation = [
"postgres",
"dep:postgres-federation",
"dep:postgres-social",
"dep:activitypub",
"federation",
"composition/postgres-federation",
]
[dependencies]
axum = { workspace = true }
@@ -55,18 +46,13 @@ async-trait = { workspace = true }
# Optional — database backends
sqlite = { workspace = true, optional = true }
postgres = { workspace = true, optional = true }
sqlite-event-queue = { workspace = true, optional = true }
postgres-event-queue = { workspace = true, optional = true }
sqlite-search = { workspace = true, optional = true }
postgres-search = { workspace = true, optional = true }
# Optional — federation
activitypub = { workspace = true, optional = true }
sqlite-federation = { workspace = true, optional = true }
sqlite-social = { workspace = true, optional = true }
postgres-federation = { workspace = true, optional = true }
postgres-social = { workspace = true, optional = true }
[dev-dependencies]
bytes = { workspace = true }

View File

@@ -16,13 +16,8 @@ use rss::RssAdapter;
use domain::ports::{DiaryExporter, DocumentParser, EventPublisher};
use infra_wiring::EventBusBackend;
#[cfg(feature = "postgres")]
use postgres_search;
#[cfg(not(any(feature = "sqlite", feature = "postgres")))]
compile_error!(
"At least one database backend must be enabled. Use --features sqlite or --features postgres"
);
#[cfg(not(feature = "sqlite"))]
compile_error!("The sqlite feature must be enabled. Use --features sqlite");
#[tokio::main]
async fn main() -> anyhow::Result<()> {
@@ -53,15 +48,15 @@ async fn wire_dependencies() -> anyhow::Result<(AppState, axum::Router)> {
let app_config = AppConfig::from_env();
let instance = domain::value_objects::InstanceIdentity::new(app_config.base_url.clone());
let database_url = std::env::var("DATABASE_URL").context("DATABASE_URL must be set")?;
let backend = std::env::var("DATABASE_BACKEND").unwrap_or_else(|_| "sqlite".to_string());
warn_if_database_backend_set();
let (auth_service, password_hasher) = composition::factory::build_auth_adapters()?;
let metadata_client = composition::factory::build_metadata_client()?;
let poster_fetcher = composition::factory::build_poster_fetcher()?;
let object_storage = composition::factory::build_object_storage()?;
let db =
composition::factory::build_database_adapters(&backend, &database_url, &instance).await?;
let db = composition::factory::build_database_adapters(&database_url, &instance).await?;
#[cfg(feature = "federation")]
let ap_content_repo = db.ap_content;
let db_pool = db.db_pool;
@@ -81,18 +76,10 @@ async fn wire_dependencies() -> anyhow::Result<(AppState, axum::Router)> {
block_query_arc,
) = {
let fed_repos = match &db_pool {
#[cfg(feature = "postgres-federation")]
composition::DbPool::Postgres(pool) => {
postgres_federation::wire(pool.clone(), instance.clone())
}
#[cfg(feature = "sqlite-federation")]
composition::DbPool::Sqlite(pool) => {
sqlite_federation::wire(pool.clone(), instance.clone())
}
#[cfg(not(feature = "sqlite-federation"))]
_ => anyhow::bail!(
"DATABASE_BACKEND={backend} federation is not supported by this build"
),
};
let ep = create_event_publisher(event_bus, &db_pool).await?;
@@ -231,12 +218,6 @@ async fn wire_dependencies() -> anyhow::Result<(AppState, axum::Router)> {
composition::DbPool::Sqlite(pool) => {
sqlite_social::create_federated_profile_query(pool.clone(), instance.clone())
}
#[cfg(feature = "postgres-federation")]
composition::DbPool::Postgres(pool) => {
postgres_social::create_federated_profile_query(pool.clone(), instance.clone())
}
#[cfg(not(feature = "sqlite-federation"))]
_ => unreachable!(),
}
}),
#[cfg(not(feature = "federation"))]
@@ -291,10 +272,6 @@ async fn create_event_publisher(
EventBusBackend::Db => {
tracing::info!("event bus: DB queue");
Ok(match db_pool {
#[cfg(feature = "postgres")]
composition::DbPool::Postgres(pool) => {
postgres_event_queue::PostgresEventQueue::create_publisher(pool.clone()).await?
}
#[cfg(feature = "sqlite")]
composition::DbPool::Sqlite(pool) => {
sqlite_event_queue::SqliteEventQueue::create_publisher(pool.clone()).await?
@@ -311,6 +288,14 @@ async fn create_event_publisher(
}
}
fn warn_if_database_backend_set() {
if let Ok(v) = std::env::var("DATABASE_BACKEND")
&& v != "sqlite"
{
tracing::warn!("DATABASE_BACKEND is ignored; SQLite is the only backend");
}
}
fn init_tracing() {
tracing_subscriber::registry()
.with(log_filter("server=debug,tower_http=debug"))