diff --git a/Cargo.lock b/Cargo.lock index 67dcf8e..32586c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,7 +40,7 @@ name = "bedrock" version = "0.1.0" dependencies = [ "serde_json", - "sql_storage", + "sql", "tokio", ] @@ -1119,7 +1119,7 @@ dependencies = [ ] [[package]] -name = "sql_storage" +name = "sql" version = "0.1.0" dependencies = [ "clusters", diff --git a/Cargo.toml b/Cargo.toml index d09f87b..7b54633 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ rust-version = "1.91" [workspace.dependencies] clusters = { path = "crates/clusters" } -sql_storage = { path = "crates/sql_storage" } +sql = { path = "crates/sql" } serde = { version = "1", features = ["derive"] } serde_json = "1" sqlx = { version = "0.8.6", default-features = false, features = ["any", "runtime-tokio", "tls-rustls-ring-webpki"] } @@ -24,6 +24,6 @@ edition.workspace = true rust-version.workspace = true [dependencies] -sql_storage.workspace = true +sql.workspace = true serde_json.workspace = true tokio.workspace = true diff --git a/README.md b/README.md index 713291d..413704e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Bedrock storage -Bedrock stores JSON documents in SQLite, PostgreSQL or MySQL. Each backend has its own module in the `sql_storage` crate. 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 `sql` crate. SQLite is the default and creates `bedrock.sqlite3` in the current directory on first start. ## Storage boundaries -`sql_storage` owns the transactional document data, revisions, and snapshots used by the application. `clusters` resolves deployment settings. The `sql_storage` connection module selects the SQL driver and read endpoints. +`sql` owns the transactional document data, revisions, and snapshots used by the application. `clusters` resolves deployment settings. The `sql` connection module selects the SQL driver and read endpoints. Notion describes sharding online PostgreSQL block data by workspace and feeding a downstream S3 data lake from PostgreSQL changes. Bedrock currently supports selecting a configured SQL cluster and using its read replicas. Workspace sharding, S3 object storage, and data-lake ingestion are future work. [Notion's PostgreSQL sharding](https://www.notion.com/blog/sharding-postgres-at-notion) · [Notion's data lake](https://www.notion.com/blog/building-and-scaling-notions-data-lake) @@ -29,7 +29,7 @@ Set `BEDROCK_DB_CONFIG` to the path of a private JSON deployment configuration t The database must already exist for PostgreSQL and MySQL. Bedrock creates its own tables and deployment row on a writable startup. Network endpoints use TLS with certificate and hostname verification by default. For a private test database without TLS, set the cluster's `tls` to `"disabled"`. A top-level `"read_only": true` opens an existing deployment without initializing it. A SQLite deployment can set `sqlite_path` to use another file. -Applications connect with `sql_storage::connect`. A write batch commits at one new revision if its expected deployment revision still matches. Reads can target the primary or prefer replicas. Use an explicit revision to require that snapshot and fall back when replicas have fallen behind. A tombstone removes a document from subsequent snapshots while preserving earlier revisions. JSON null remains a stored value. +Applications connect with `sql::connect`. A write batch commits at one new revision if its expected deployment revision still matches. Reads can target the primary or prefer replicas. Use an explicit revision to require that snapshot and fall back when replicas have fallen behind. A tombstone removes a document from subsequent snapshots while preserving earlier revisions. JSON null remains a stored value. For MySQL, use `Connection::mysql_writer` to acquire, renew or release a writer lease. An active lease blocks ordinary writes. Use `commit_with_lease` while holding it. `delete_deployment` requires an active lease, deletes that deployment's documents and permanently retires its ID in the database. diff --git a/crates/sql_storage/Cargo.toml b/crates/sql/Cargo.toml similarity index 93% rename from crates/sql_storage/Cargo.toml rename to crates/sql/Cargo.toml index 6c143ed..65cf2b4 100644 --- a/crates/sql_storage/Cargo.toml +++ b/crates/sql/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "sql_storage" +name = "sql" version = "0.1.0" edition.workspace = true rust-version.workspace = true diff --git a/crates/sql_storage/src/connection.rs b/crates/sql/src/connection.rs similarity index 100% rename from crates/sql_storage/src/connection.rs rename to crates/sql/src/connection.rs diff --git a/crates/sql_storage/src/lib.rs b/crates/sql/src/lib.rs similarity index 100% rename from crates/sql_storage/src/lib.rs rename to crates/sql/src/lib.rs diff --git a/crates/sql_storage/src/mysql.rs b/crates/sql/src/mysql.rs similarity index 100% rename from crates/sql_storage/src/mysql.rs rename to crates/sql/src/mysql.rs diff --git a/crates/sql_storage/src/postgres.rs b/crates/sql/src/postgres.rs similarity index 100% rename from crates/sql_storage/src/postgres.rs rename to crates/sql/src/postgres.rs diff --git a/crates/sql_storage/src/sqlite.rs b/crates/sql/src/sqlite.rs similarity index 100% rename from crates/sql_storage/src/sqlite.rs rename to crates/sql/src/sqlite.rs diff --git a/crates/sql_storage/tests/storage.rs b/crates/sql/tests/storage.rs similarity index 99% rename from crates/sql_storage/tests/storage.rs rename to crates/sql/tests/storage.rs index 8631144..96580a8 100644 --- a/crates/sql_storage/tests/storage.rs +++ b/crates/sql/tests/storage.rs @@ -1,7 +1,7 @@ use std::{collections::BTreeMap, env, time::Duration}; use serde_json::json; -use sql_storage::{ +use sql::{ Cluster, Connection, DeploymentConfig, Driver, Mutation, ReadPreference, StorageError, Tls, connect, }; diff --git a/deploy/README.md b/deploy/README.md index e253b9f..756d0ab 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -6,7 +6,7 @@ Deployments pass the path of a JSON configuration file to the Bedrock executable - **PostgreSQL** injects the Gitea Actions variable values `BEDROCK_PG_HOST`, `BEDROCK_PG_PORT`, `BEDROCK_PG_DATABASE` and `BEDROCK_PG_USER`, and the secret `BEDROCK_PG_PASSWORD`, into the deployment step. Run `python3 deploy/render-postgres.py /path/to/private/bedrock.json --deployment production`. The renderer writes a private file and does not print its contents. Mount that file for the Bedrock service and set `BEDROCK_DB_CONFIG` to the mounted path. The configured database must already exist and the server must present a trusted certificate matching the database address. - **MySQL** accepts the same cluster shape described in the [storage configuration](../README.md) with `"driver": "mysql"` and a `mysql://` endpoint. -Keep `BEDROCK_S3_SECRET_KEY`, `BEDROCK_S3_ENDPOINT`, and `BEDROCK_S3_ACCESS_KEY` scoped to the deployment that consumes object storage. S3 integration is pending. The PostgreSQL renderer and `sql_storage` use only SQL configuration. +Keep `BEDROCK_S3_SECRET_KEY`, `BEDROCK_S3_ENDPOINT`, and `BEDROCK_S3_ACCESS_KEY` scoped to the deployment that consumes object storage. S3 integration is pending. The PostgreSQL renderer and `sql` use only SQL configuration. Pull requests currently run without an automatic storage check. The optional `ci/check-sql.sh` script uses isolated database containers and generated fixture credentials when run on an approved remote runner. diff --git a/deploy/bedrock-deployment.svg b/deploy/bedrock-deployment.svg index 0b15e4d..9733078 100644 --- a/deploy/bedrock-deployment.svg +++ b/deploy/bedrock-deployment.svg @@ -72,11 +72,11 @@ Rust Bedrock 读取配置 -通过 sql_storage::connect 选择 postgres。 +通过 sql::connect 选择 postgres。 配置由 BEDROCK_DB_CONFIG 指定。 在已有 PostgreSQL 数据库内初始化 -postgres 模块提供 SQL,sql_storage 在事务里执行。 +postgres 模块提供 SQL,sql 在事务里执行。 创建 Bedrock 表并登记 production 部署。 进入 Store::initialize() 成功 diff --git a/src/main.rs b/src/main.rs index 604cba9..9404e66 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use std::{env, error::Error, fs}; -use sql_storage::{DeploymentConfig, connect}; +use sql::{DeploymentConfig, connect}; #[tokio::main] async fn main() -> Result<(), Box> {