diff --git a/CLAUDE.md b/CLAUDE.md index fe1f4ba..169457e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -7,7 +7,7 @@ Brewlog is a self-hosted coffee logging platform built in Rust. It provides: - HTTP server with web UI (Axum + Askama templates + Datastar) - REST API for programmatic access - CLI client for command-line operations -- SQLite/PostgreSQL database support (feature-flagged) +- SQLite database ## Build & Test Commands diff --git a/Cargo.toml b/Cargo.toml index 5d3c76a..d5bee96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,11 +3,6 @@ name = "brewlog" version = "0.1.0" edition = "2024" -[features] -default = ["sqlite"] -sqlite = ["sqlx/sqlite"] -postgres = ["sqlx/postgres"] - [dependencies] anyhow = "1.0" async-trait = "0.1" @@ -29,7 +24,7 @@ sqlx = { version = "0.7", default-features = false, features = [ "tls-rustls", "macros", "chrono", - "any", + "sqlite", "migrate", ] } thiserror = "1.0" diff --git a/README.md b/README.md index 44b2e48..eba7161 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ CLI client. - **CLI client** for terminal-based workflows - **AI extraction** — scan a coffee bag label or type a description to auto-fill forms (via [OpenRouter](https://openrouter.ai/)) - **Nearby cafe search** powered by [Foursquare Places](https://docs.foursquare.com/developer/reference/place-search) -- **SQLite** (default) or **PostgreSQL** (compile-time feature flag) +- **SQLite** database - **Passkey authentication** — no passwords, WebAuthn only ## Quick Start @@ -19,8 +19,6 @@ CLI client. ```bash cargo install --git https://github.com/jnsgruk/brewlog.git -# For PostgreSQL instead of SQLite: -# cargo install --git https://github.com/jnsgruk/brewlog.git --no-default-features --features postgres ``` ### Configure @@ -102,14 +100,7 @@ directory is loaded automatically via [dotenvy](https://crates.io/crates/dotenvy ### Database -SQLite is the default. PostgreSQL is supported via a compile-time feature flag: - -```bash -cargo build --release # SQLite -cargo build --release --features postgres --no-default-features # PostgreSQL -``` - -Migrations run automatically on server startup. +SQLite is used for storage. Migrations run automatically on server startup. ## Contributing diff --git a/src/infrastructure/database.rs b/src/infrastructure/database.rs index 6718b4d..c181d5f 100644 --- a/src/infrastructure/database.rs +++ b/src/infrastructure/database.rs @@ -1,41 +1,18 @@ use anyhow::Context; use sqlx::migrate::Migrator; -#[cfg(all(feature = "sqlite", feature = "postgres"))] -compile_error!("features `sqlite` and `postgres` cannot both be enabled"); - -#[cfg(not(any(feature = "sqlite", feature = "postgres")))] -compile_error!("enable either the `sqlite` or `postgres` feature"); - -#[cfg(feature = "sqlite")] pub type DatabasePool = sqlx::SqlitePool; -#[cfg(feature = "sqlite")] type PoolOptions = sqlx::sqlite::SqlitePoolOptions; -#[cfg(feature = "sqlite")] pub type DatabaseTransaction<'a> = sqlx::Transaction<'a, sqlx::Sqlite>; -#[cfg(feature = "sqlite")] pub type DatabaseRow = sqlx::sqlite::SqliteRow; -#[cfg(feature = "sqlite")] pub type DatabaseDriver = sqlx::Sqlite; -#[cfg(feature = "postgres")] -pub type DatabasePool = sqlx::PgPool; -#[cfg(feature = "postgres")] -type PoolOptions = sqlx::postgres::PgPoolOptions; -#[cfg(feature = "postgres")] -pub type DatabaseTransaction<'a> = sqlx::Transaction<'a, sqlx::Postgres>; -#[cfg(feature = "postgres")] -pub type DatabaseRow = sqlx::postgres::PgRow; -#[cfg(feature = "postgres")] -pub type DatabaseDriver = sqlx::Postgres; - pub struct Database { pool: DatabasePool, } impl Database { pub async fn connect(database_url: &str) -> anyhow::Result { - #[cfg(feature = "sqlite")] let pool = { use sqlx::sqlite::SqliteConnectOptions; use std::str::FromStr; @@ -51,20 +28,10 @@ impl Database { .with_context(|| format!("failed to connect to database: {database_url}"))? }; - #[cfg(feature = "postgres")] - let pool = PoolOptions::new() - .max_connections(5) - .connect(database_url) + sqlx::query("PRAGMA foreign_keys = ON;") + .execute(&pool) .await - .with_context(|| format!("failed to connect to database: {database_url}"))?; - - #[cfg(feature = "sqlite")] - { - sqlx::query("PRAGMA foreign_keys = ON;") - .execute(&pool) - .await - .context("failed to enable foreign keys for sqlite")?; - } + .context("failed to enable foreign keys for sqlite")?; let db = Self { pool }; db.migrate().await?;