From 2f2a39621cc161bcd63086a109aa951996790d3a Mon Sep 17 00:00:00 2001 From: Codex Bot Date: Mon, 30 Nov 2026 03:43:47 +0800 Subject: [PATCH] Consolidate SQL backends into persistence modules --- Cargo.lock | 28 ------------------- Cargo.toml | 3 -- README.md | 2 +- crates/db_connection/Cargo.toml | 4 --- crates/db_connection/src/lib.rs | 4 +-- crates/mysql/Cargo.toml | 9 ------ crates/persistence/Cargo.toml | 2 +- crates/persistence/src/lib.rs | 6 +++- .../src/lib.rs => persistence/src/mysql.rs} | 2 +- .../lib.rs => persistence/src/postgres.rs} | 2 +- .../src/lib.rs => persistence/src/sqlite.rs} | 2 +- crates/postgres/Cargo.toml | 9 ------ crates/sqlite/Cargo.toml | 9 ------ deploy/bedrock-deployment.svg | 2 +- 14 files changed, 13 insertions(+), 71 deletions(-) delete mode 100644 crates/mysql/Cargo.toml rename crates/{mysql/src/lib.rs => persistence/src/mysql.rs} (99%) rename crates/{postgres/src/lib.rs => persistence/src/postgres.rs} (95%) rename crates/{sqlite/src/lib.rs => persistence/src/sqlite.rs} (95%) delete mode 100644 crates/postgres/Cargo.toml delete mode 100644 crates/sqlite/Cargo.toml diff --git a/Cargo.lock b/Cargo.lock index fb16ff8..b23b241 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -159,12 +159,8 @@ name = "db_connection" version = "0.1.0" dependencies = [ "clusters", - "mysql", "persistence", - "postgres", "serde_json", - "sqlite", - "sqlx", "tempfile", "thiserror", "tokio", @@ -680,14 +676,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "mysql" -version = "0.1.0" -dependencies = [ - "persistence", - "sqlx", -] - [[package]] name = "num-bigint-dig" version = "0.8.6" @@ -831,14 +819,6 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" -[[package]] -name = "postgres" -version = "0.1.0" -dependencies = [ - "persistence", - "sqlx", -] - [[package]] name = "potential_utf" version = "0.1.6" @@ -1159,14 +1139,6 @@ dependencies = [ "der", ] -[[package]] -name = "sqlite" -version = "0.1.0" -dependencies = [ - "persistence", - "sqlx", -] - [[package]] name = "sqlx" version = "0.8.6" diff --git a/Cargo.toml b/Cargo.toml index 533566c..c574d7a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,9 +10,6 @@ rust-version = "1.91" clusters = { path = "crates/clusters" } db_connection = { path = "crates/db_connection" } persistence = { path = "crates/persistence" } -sqlite = { path = "crates/sqlite" } -postgres = { path = "crates/postgres" } -mysql = { path = "crates/mysql" } serde = { version = "1", features = ["derive"] } serde_json = "1" sqlx = { version = "0.8.6", default-features = false, features = ["any", "runtime-tokio", "tls-rustls-ring-webpki"] } diff --git a/README.md b/README.md index 1103162..0365b65 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Bedrock storage -Bedrock stores JSON documents in SQLite, PostgreSQL or MySQL. SQLite is the default and creates `bedrock.sqlite3` in the current directory on first start. +Bedrock stores JSON documents in SQLite, PostgreSQL or MySQL. Each backend has its own module in the `persistence` crate. SQLite is the default and creates `bedrock.sqlite3` in the current directory on first start. Set `BEDROCK_DB_CONFIG` to the path of a private JSON deployment configuration to select a different cluster. For example: diff --git a/crates/db_connection/Cargo.toml b/crates/db_connection/Cargo.toml index 13b09a1..2ac602b 100644 --- a/crates/db_connection/Cargo.toml +++ b/crates/db_connection/Cargo.toml @@ -6,14 +6,10 @@ rust-version.workspace = true [dependencies] clusters.workspace = true -mysql.workspace = true persistence.workspace = true -postgres.workspace = true -sqlite.workspace = true thiserror.workspace = true [dev-dependencies] serde_json.workspace = true -sqlx = { workspace = true, features = ["mysql", "postgres", "sqlite"] } tempfile.workspace = true tokio.workspace = true diff --git a/crates/db_connection/src/lib.rs b/crates/db_connection/src/lib.rs index 23f6b92..2dc78d9 100644 --- a/crates/db_connection/src/lib.rs +++ b/crates/db_connection/src/lib.rs @@ -3,11 +3,11 @@ use std::sync::atomic::{AtomicUsize, Ordering}; pub use clusters::{Address, Cluster, ConfigError, DeploymentConfig, Driver, Tls}; -pub use mysql::{Lease, MySql}; +pub use persistence::mysql::{Lease, MySql}; pub use persistence::{Document, Error as StorageError, Mutation, Revision, Snapshot}; use clusters::ResolvedDeployment; -use persistence::{Reader, Store}; +use persistence::{Reader, Store, mysql, postgres, sqlite}; use thiserror::Error; #[derive(Debug, Error)] diff --git a/crates/mysql/Cargo.toml b/crates/mysql/Cargo.toml deleted file mode 100644 index c9b0559..0000000 --- a/crates/mysql/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "mysql" -version = "0.1.0" -edition.workspace = true -rust-version.workspace = true - -[dependencies] -persistence.workspace = true -sqlx = { workspace = true, features = ["mysql"] } diff --git a/crates/persistence/Cargo.toml b/crates/persistence/Cargo.toml index bf27ee2..8b7ed65 100644 --- a/crates/persistence/Cargo.toml +++ b/crates/persistence/Cargo.toml @@ -6,5 +6,5 @@ rust-version.workspace = true [dependencies] serde_json.workspace = true -sqlx.workspace = true +sqlx = { workspace = true, features = ["mysql", "postgres", "sqlite"] } thiserror.workspace = true diff --git a/crates/persistence/src/lib.rs b/crates/persistence/src/lib.rs index 51cb518..dedbf43 100644 --- a/crates/persistence/src/lib.rs +++ b/crates/persistence/src/lib.rs @@ -1,4 +1,8 @@ -//! Shared storage contract for Bedrock's SQL backends. +//! Shared storage contract and SQL backends for Bedrock. + +pub mod mysql; +pub mod postgres; +pub mod sqlite; use std::{borrow::Cow, collections::HashSet, fmt::Write, time::Duration}; diff --git a/crates/mysql/src/lib.rs b/crates/persistence/src/mysql.rs similarity index 99% rename from crates/mysql/src/lib.rs rename to crates/persistence/src/mysql.rs index 031d506..e1a1e6d 100644 --- a/crates/mysql/src/lib.rs +++ b/crates/persistence/src/mysql.rs @@ -2,7 +2,7 @@ use std::{sync::Arc, time::Duration}; -use persistence::{ +use crate::{ Dialect, Error, MYSQL_NOW, Mutation, Reader, Result, Revision, Store, lock_mysql_deployment, pool, }; diff --git a/crates/postgres/src/lib.rs b/crates/persistence/src/postgres.rs similarity index 95% rename from crates/postgres/src/lib.rs rename to crates/persistence/src/postgres.rs index 343c898..612dad9 100644 --- a/crates/postgres/src/lib.rs +++ b/crates/persistence/src/postgres.rs @@ -1,6 +1,6 @@ //! PostgreSQL connection pools and the Bedrock document layout. -use persistence::{Dialect, Reader, Result, Store, pool}; +use crate::{Dialect, Reader, Result, Store, pool}; const SCHEMA: &[&str] = &[ "CREATE TABLE IF NOT EXISTS bedrock_deployments ( diff --git a/crates/sqlite/src/lib.rs b/crates/persistence/src/sqlite.rs similarity index 95% rename from crates/sqlite/src/lib.rs rename to crates/persistence/src/sqlite.rs index 09b483f..ee3ce1e 100644 --- a/crates/sqlite/src/lib.rs +++ b/crates/persistence/src/sqlite.rs @@ -1,6 +1,6 @@ //! File-backed Bedrock storage for self-hosted deployments. -use persistence::{Dialect, Reader, Result, Store, pool}; +use crate::{Dialect, Reader, Result, Store, pool}; const SCHEMA: &[&str] = &[ "CREATE TABLE IF NOT EXISTS bedrock_deployments ( diff --git a/crates/postgres/Cargo.toml b/crates/postgres/Cargo.toml deleted file mode 100644 index 195f869..0000000 --- a/crates/postgres/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "postgres" -version = "0.1.0" -edition.workspace = true -rust-version.workspace = true - -[dependencies] -persistence.workspace = true -sqlx = { workspace = true, features = ["postgres"] } diff --git a/crates/sqlite/Cargo.toml b/crates/sqlite/Cargo.toml deleted file mode 100644 index 93e2f00..0000000 --- a/crates/sqlite/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "sqlite" -version = "0.1.0" -edition.workspace = true -rust-version.workspace = true - -[dependencies] -persistence.workspace = true -sqlx = { workspace = true, features = ["sqlite"] } diff --git a/deploy/bedrock-deployment.svg b/deploy/bedrock-deployment.svg index 59c165d..2f62e66 100644 --- a/deploy/bedrock-deployment.svg +++ b/deploy/bedrock-deployment.svg @@ -76,7 +76,7 @@ 配置由 BEDROCK_DB_CONFIG 指定。 在已有 PostgreSQL 数据库内初始化 -postgres 提供 SQL,persistence 在事务里执行。 +postgres 模块提供 SQL,共用存储层在事务里执行。 创建 Bedrock 表并登记 production 部署。 进入 Store::initialize() 成功