refactor: remove PostgreSQL feature-flagged support
- Remove sqlite/postgres feature flags from Cargo.toml - Replace "any" sqlx feature with direct "sqlite" feature - Remove all #[cfg] conditional compilation from database.rs - Update README.md and CLAUDE.md to reflect SQLite-only support
This commit is contained in:
parent
765acf5d6b
commit
a6eaf26814
4 changed files with 7 additions and 54 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
13
README.md
13
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
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Self> {
|
||||
#[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)
|
||||
.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")?;
|
||||
}
|
||||
|
||||
let db = Self { pool };
|
||||
db.migrate().await?;
|
||||
|
|
|
|||
Loading…
Reference in a new issue