refactor: collapse feature flags to federation+nats
This commit is contained in:
@@ -5,10 +5,8 @@ edition.workspace = true
|
||||
|
||||
[features]
|
||||
default = []
|
||||
sqlite = ["dep:sqlite", "dep:sqlite-event-queue", "dep:sqlite-search", "dep:sqlite-social", "infra-wiring/sqlite"]
|
||||
nats = ["dep:nats", "infra-wiring/nats"]
|
||||
federation = ["application/federation"]
|
||||
sqlite-federation = ["sqlite", "dep:sqlite-federation", "dep:activitypub", "federation"]
|
||||
federation = ["application/federation", "dep:sqlite-federation", "dep:activitypub"]
|
||||
|
||||
[dependencies]
|
||||
domain = { workspace = true }
|
||||
@@ -21,11 +19,12 @@ object-storage = { workspace = true }
|
||||
jellyfin = { workspace = true }
|
||||
plex = { workspace = true }
|
||||
anyhow = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
|
||||
sqlite = { workspace = true, optional = true }
|
||||
sqlite-event-queue = { workspace = true, optional = true }
|
||||
sqlite-search = { workspace = true, optional = true }
|
||||
sqlite-social = { workspace = true, optional = true }
|
||||
sqlite = { workspace = true }
|
||||
sqlite-event-queue = { workspace = true }
|
||||
sqlite-search = { workspace = true }
|
||||
sqlite-social = { workspace = true }
|
||||
nats = { workspace = true, optional = true }
|
||||
activitypub = { workspace = true, optional = true }
|
||||
sqlite-federation = { workspace = true, optional = true }
|
||||
|
||||
@@ -123,9 +123,14 @@ pub fn build_profile_fields_repo(
|
||||
pool: &DbPool,
|
||||
) -> anyhow::Result<Arc<dyn UserProfileFieldsRepository>> {
|
||||
match pool {
|
||||
#[cfg(feature = "sqlite")]
|
||||
DbPool::Sqlite(pool) => Ok(sqlite::create_profile_fields_repo(pool.clone())),
|
||||
#[cfg(not(feature = "sqlite"))]
|
||||
_ => anyhow::bail!("no profile fields repo for this backend"),
|
||||
}
|
||||
}
|
||||
|
||||
pub 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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,11 +265,7 @@ fn test_repositories() -> Repositories {
|
||||
}
|
||||
|
||||
/// A lazily-connected in-memory sqlite pool — never actually opened in this test,
|
||||
/// just a value to satisfy `DatabaseOutput::db_pool`. Requires the `sqlite` feature,
|
||||
/// which `cargo test --workspace` enables transitively (presentation/worker both
|
||||
/// default to it), matching how `DbPool::Sqlite` is only constructible under that
|
||||
/// feature everywhere else in the workspace.
|
||||
#[cfg(feature = "sqlite")]
|
||||
/// just a value to satisfy `DatabaseOutput::db_pool`.
|
||||
fn test_db_pool() -> infra_wiring::DbPool {
|
||||
let pool = sqlx::sqlite::SqlitePoolOptions::new()
|
||||
.connect_lazy("sqlite::memory:")
|
||||
@@ -277,14 +273,6 @@ fn test_db_pool() -> infra_wiring::DbPool {
|
||||
infra_wiring::DbPool::Sqlite(pool)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "sqlite"))]
|
||||
fn test_db_pool() -> infra_wiring::DbPool {
|
||||
unreachable!(
|
||||
"worker_deps_wiring needs the sqlite feature; cargo test --workspace enables it \
|
||||
transitively via presentation/worker's default features"
|
||||
)
|
||||
}
|
||||
|
||||
fn test_database_output() -> DatabaseOutput {
|
||||
let movies = InMemoryMovieRepository::new();
|
||||
let watch_events = InMemoryWatchEventRepository::new();
|
||||
|
||||
@@ -9,5 +9,4 @@ anyhow = { workspace = true }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
sqlite = []
|
||||
nats = []
|
||||
|
||||
@@ -3,7 +3,6 @@ pub mod config;
|
||||
pub use config::{AppConfig, WrapUpConfig};
|
||||
|
||||
pub enum DbPool {
|
||||
#[cfg(feature = "sqlite")]
|
||||
Sqlite(sqlx::SqlitePool),
|
||||
}
|
||||
|
||||
|
||||
@@ -495,7 +495,6 @@ impl SearchCommand for Panic {
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "federation")]
|
||||
#[async_trait::async_trait]
|
||||
impl domain::ports::RemoteWatchlistRepository for Panic {
|
||||
async fn save(&self, _: domain::models::RemoteWatchlistEntry) -> Result<(), DomainError> {
|
||||
|
||||
@@ -6,19 +6,18 @@ description = "Self-hosted movie diary with REST API and ActivityPub federation"
|
||||
license = "MIT"
|
||||
|
||||
[features]
|
||||
default = ["sqlite", "sqlite-federation"]
|
||||
sqlite = ["dep:sqlite", "dep:sqlite-event-queue", "dep:sqlite-search", "infra-wiring/sqlite", "composition/sqlite"]
|
||||
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"]
|
||||
sqlite-federation = [
|
||||
"sqlite",
|
||||
"dep:sqlite-federation",
|
||||
"dep:sqlite-social",
|
||||
default = ["federation"]
|
||||
federation = [
|
||||
"dep:activitypub",
|
||||
"federation",
|
||||
"composition/sqlite-federation",
|
||||
"dep:sqlite-federation",
|
||||
"application/federation",
|
||||
"presentation/federation",
|
||||
"composition/federation",
|
||||
]
|
||||
nats = ["dep:nats", "infra-wiring/nats", "composition/nats"]
|
||||
# deprecated aliases kept so existing deploy commands keep working
|
||||
sqlite = []
|
||||
sqlite-federation = ["federation"]
|
||||
|
||||
[dependencies]
|
||||
axum = { workspace = true }
|
||||
@@ -44,15 +43,14 @@ sqlx = { workspace = true }
|
||||
infra-wiring = { workspace = true }
|
||||
async-trait = { workspace = true }
|
||||
|
||||
# Optional — database backends
|
||||
sqlite = { workspace = true, optional = true }
|
||||
sqlite-event-queue = { workspace = true, optional = true }
|
||||
sqlite-search = { workspace = true, optional = true }
|
||||
sqlite = { workspace = true }
|
||||
sqlite-event-queue = { workspace = true }
|
||||
sqlite-search = { workspace = true }
|
||||
sqlite-social = { workspace = true }
|
||||
|
||||
# Optional — federation
|
||||
activitypub = { workspace = true, optional = true }
|
||||
activitypub = { workspace = true, optional = true }
|
||||
sqlite-federation = { workspace = true, optional = true }
|
||||
sqlite-social = { workspace = true, optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
bytes = { workspace = true }
|
||||
|
||||
@@ -16,9 +16,6 @@ use rss::RssAdapter;
|
||||
use domain::ports::{DiaryExporter, DocumentParser, EventPublisher};
|
||||
use infra_wiring::EventBusBackend;
|
||||
|
||||
#[cfg(not(feature = "sqlite"))]
|
||||
compile_error!("The sqlite feature must be enabled. Use --features sqlite");
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
dotenvy::dotenv().ok();
|
||||
@@ -48,7 +45,7 @@ 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")?;
|
||||
warn_if_database_backend_set();
|
||||
composition::factory::warn_if_database_backend_set();
|
||||
|
||||
let (auth_service, password_hasher) = composition::factory::build_auth_adapters()?;
|
||||
let metadata_client = composition::factory::build_metadata_client()?;
|
||||
@@ -76,7 +73,6 @@ async fn wire_dependencies() -> anyhow::Result<(AppState, axum::Router)> {
|
||||
block_query_arc,
|
||||
) = {
|
||||
let fed_repos = match &db_pool {
|
||||
#[cfg(feature = "sqlite-federation")]
|
||||
composition::DbPool::Sqlite(pool) => {
|
||||
sqlite_federation::wire(pool.clone(), instance.clone())
|
||||
}
|
||||
@@ -214,7 +210,6 @@ async fn wire_dependencies() -> anyhow::Result<(AppState, axum::Router)> {
|
||||
#[cfg(feature = "federation")]
|
||||
federated_profile: Some({
|
||||
match &db_pool {
|
||||
#[cfg(feature = "sqlite-federation")]
|
||||
composition::DbPool::Sqlite(pool) => {
|
||||
sqlite_social::create_federated_profile_query(pool.clone(), instance.clone())
|
||||
}
|
||||
@@ -272,7 +267,6 @@ async fn create_event_publisher(
|
||||
EventBusBackend::Db => {
|
||||
tracing::info!("event bus: DB queue");
|
||||
Ok(match db_pool {
|
||||
#[cfg(feature = "sqlite")]
|
||||
composition::DbPool::Sqlite(pool) => {
|
||||
sqlite_event_queue::SqliteEventQueue::create_publisher(pool.clone()).await?
|
||||
}
|
||||
@@ -288,14 +282,6 @@ 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"))
|
||||
|
||||
@@ -362,9 +362,7 @@ impl SearchCommand for PanicSearchCommand {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "federation")]
|
||||
struct PanicRemoteWatchlist;
|
||||
#[cfg(feature = "federation")]
|
||||
#[async_trait::async_trait]
|
||||
impl domain::ports::RemoteWatchlistRepository for PanicRemoteWatchlist {
|
||||
async fn save(&self, _: domain::models::RemoteWatchlistEntry) -> Result<(), DomainError> {
|
||||
|
||||
@@ -4,17 +4,17 @@ version = "0.1.0"
|
||||
edition.workspace = true
|
||||
|
||||
[features]
|
||||
default = ["sqlite", "sqlite-federation"]
|
||||
sqlite = ["dep:sqlite", "dep:sqlite-event-queue", "dep:sqlite-search", "infra-wiring/sqlite", "composition/sqlite"]
|
||||
nats = ["dep:nats", "infra-wiring/nats", "composition/nats"]
|
||||
federation = ["application/federation"]
|
||||
sqlite-federation = [
|
||||
"sqlite",
|
||||
"dep:sqlite-federation",
|
||||
default = ["federation"]
|
||||
federation = [
|
||||
"dep:activitypub",
|
||||
"federation",
|
||||
"composition/sqlite-federation",
|
||||
"dep:sqlite-federation",
|
||||
"application/federation",
|
||||
"composition/federation",
|
||||
]
|
||||
nats = ["dep:nats", "infra-wiring/nats", "composition/nats"]
|
||||
# deprecated aliases kept so existing deploy commands keep working
|
||||
sqlite = []
|
||||
sqlite-federation = ["federation"]
|
||||
|
||||
[dependencies]
|
||||
domain = { workspace = true }
|
||||
@@ -39,11 +39,10 @@ sqlx = { workspace = true }
|
||||
infra-wiring = { workspace = true }
|
||||
async-trait = { workspace = true }
|
||||
|
||||
# Optional — database backends
|
||||
sqlite = { workspace = true, optional = true }
|
||||
sqlite-event-queue = { workspace = true, optional = true }
|
||||
sqlite-search = { workspace = true, optional = true }
|
||||
sqlite = { workspace = true }
|
||||
sqlite-event-queue = { workspace = true }
|
||||
sqlite-search = { workspace = true }
|
||||
|
||||
# Optional — federation
|
||||
activitypub = { workspace = true, optional = true }
|
||||
activitypub = { workspace = true, optional = true }
|
||||
sqlite-federation = { workspace = true, optional = true }
|
||||
|
||||
@@ -13,7 +13,6 @@ pub async fn create(
|
||||
EventBusBackend::Db => {
|
||||
tracing::info!("event bus: DB queue");
|
||||
match db_pool {
|
||||
#[cfg(feature = "sqlite")]
|
||||
DbPool::Sqlite(pool) => {
|
||||
Ok(sqlite_event_queue::SqliteEventQueue::create_channel(pool.clone()).await?)
|
||||
}
|
||||
|
||||
@@ -13,16 +13,13 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
use domain::ports::{EventHandler, MovieEnrichmentClient, PeriodicJob, PersonEnrichmentClient};
|
||||
|
||||
#[cfg(not(feature = "sqlite"))]
|
||||
compile_error!("The sqlite feature must be enabled. Use --features sqlite");
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
dotenvy::dotenv().ok();
|
||||
init_tracing();
|
||||
|
||||
let database_url = std::env::var("DATABASE_URL").context("DATABASE_URL must be set")?;
|
||||
warn_if_database_backend_set();
|
||||
composition::factory::warn_if_database_backend_set();
|
||||
let app_config = AppConfig::from_env();
|
||||
let instance = domain::value_objects::InstanceIdentity::new(app_config.base_url.clone());
|
||||
|
||||
@@ -82,7 +79,6 @@ async fn main() -> anyhow::Result<()> {
|
||||
// Wire federation repos early to get remote_watchlist_repo for AppContext.
|
||||
#[cfg(feature = "federation")]
|
||||
let fed_repos = match &db.db_pool {
|
||||
#[cfg(feature = "sqlite-federation")]
|
||||
composition::DbPool::Sqlite(pool) => {
|
||||
sqlite_federation::wire(pool.clone(), instance.clone())
|
||||
}
|
||||
@@ -301,14 +297,6 @@ async fn main() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
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("worker=info,application=info,k_ap=info"))
|
||||
|
||||
Reference in New Issue
Block a user