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)
|
- HTTP server with web UI (Axum + Askama templates + Datastar)
|
||||||
- REST API for programmatic access
|
- REST API for programmatic access
|
||||||
- CLI client for command-line operations
|
- CLI client for command-line operations
|
||||||
- SQLite/PostgreSQL database support (feature-flagged)
|
- SQLite database
|
||||||
|
|
||||||
## Build & Test Commands
|
## Build & Test Commands
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,6 @@ name = "brewlog"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["sqlite"]
|
|
||||||
sqlite = ["sqlx/sqlite"]
|
|
||||||
postgres = ["sqlx/postgres"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
|
|
@ -29,7 +24,7 @@ sqlx = { version = "0.7", default-features = false, features = [
|
||||||
"tls-rustls",
|
"tls-rustls",
|
||||||
"macros",
|
"macros",
|
||||||
"chrono",
|
"chrono",
|
||||||
"any",
|
"sqlite",
|
||||||
"migrate",
|
"migrate",
|
||||||
] }
|
] }
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
|
|
|
||||||
13
README.md
13
README.md
|
|
@ -9,7 +9,7 @@ CLI client.
|
||||||
- **CLI client** for terminal-based workflows
|
- **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/))
|
- **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)
|
- **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
|
- **Passkey authentication** — no passwords, WebAuthn only
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
@ -19,8 +19,6 @@ CLI client.
|
||||||
```bash
|
```bash
|
||||||
cargo install --git https://github.com/jnsgruk/brewlog.git
|
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
|
### Configure
|
||||||
|
|
@ -102,14 +100,7 @@ directory is loaded automatically via [dotenvy](https://crates.io/crates/dotenvy
|
||||||
|
|
||||||
### Database
|
### Database
|
||||||
|
|
||||||
SQLite is the default. PostgreSQL is supported via a compile-time feature flag:
|
SQLite is used for storage. Migrations run automatically on server startup.
|
||||||
|
|
||||||
```bash
|
|
||||||
cargo build --release # SQLite
|
|
||||||
cargo build --release --features postgres --no-default-features # PostgreSQL
|
|
||||||
```
|
|
||||||
|
|
||||||
Migrations run automatically on server startup.
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,41 +1,18 @@
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use sqlx::migrate::Migrator;
|
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;
|
pub type DatabasePool = sqlx::SqlitePool;
|
||||||
#[cfg(feature = "sqlite")]
|
|
||||||
type PoolOptions = sqlx::sqlite::SqlitePoolOptions;
|
type PoolOptions = sqlx::sqlite::SqlitePoolOptions;
|
||||||
#[cfg(feature = "sqlite")]
|
|
||||||
pub type DatabaseTransaction<'a> = sqlx::Transaction<'a, sqlx::Sqlite>;
|
pub type DatabaseTransaction<'a> = sqlx::Transaction<'a, sqlx::Sqlite>;
|
||||||
#[cfg(feature = "sqlite")]
|
|
||||||
pub type DatabaseRow = sqlx::sqlite::SqliteRow;
|
pub type DatabaseRow = sqlx::sqlite::SqliteRow;
|
||||||
#[cfg(feature = "sqlite")]
|
|
||||||
pub type DatabaseDriver = sqlx::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 {
|
pub struct Database {
|
||||||
pool: DatabasePool,
|
pool: DatabasePool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Database {
|
impl Database {
|
||||||
pub async fn connect(database_url: &str) -> anyhow::Result<Self> {
|
pub async fn connect(database_url: &str) -> anyhow::Result<Self> {
|
||||||
#[cfg(feature = "sqlite")]
|
|
||||||
let pool = {
|
let pool = {
|
||||||
use sqlx::sqlite::SqliteConnectOptions;
|
use sqlx::sqlite::SqliteConnectOptions;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
@ -51,20 +28,10 @@ impl Database {
|
||||||
.with_context(|| format!("failed to connect to database: {database_url}"))?
|
.with_context(|| format!("failed to connect to database: {database_url}"))?
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "postgres")]
|
sqlx::query("PRAGMA foreign_keys = ON;")
|
||||||
let pool = PoolOptions::new()
|
.execute(&pool)
|
||||||
.max_connections(5)
|
|
||||||
.connect(database_url)
|
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("failed to connect to database: {database_url}"))?;
|
.context("failed to enable foreign keys for sqlite")?;
|
||||||
|
|
||||||
#[cfg(feature = "sqlite")]
|
|
||||||
{
|
|
||||||
sqlx::query("PRAGMA foreign_keys = ON;")
|
|
||||||
.execute(&pool)
|
|
||||||
.await
|
|
||||||
.context("failed to enable foreign keys for sqlite")?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let db = Self { pool };
|
let db = Self { pool };
|
||||||
db.migrate().await?;
|
db.migrate().await?;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue