refactor: replace 19 hand-written db modules with generated code Each db module now re-exports its Row type and CRUD functions from db::generated, keeping only custom query functions (list_for_repo, search, counter increments, etc.). - Replaced struct definitions with re-exports from generated::types - Replaced upsert/delete/get/list with re-exports from generated::crud - Kept 35 custom query functions that can't be generated from Lexicons - Updated consumer.rs: actor_profile uses from_json(), fixed Option types for default_branch/visibility, added cursor param to node::list - Updated profile_put.rs: added rkey field - Updated repo_create.rs: Option<String> for default_branch/visibility - Fixed delete signature for ref_update (uses committer_did, not PK) - Fixed issue/pull get to use custom (repo_did, repo_name, rkey) lookup Net: -1,076 lines of hand-written SQL and struct definitions.

Author: Aaron Steven White
Commit 4d7aaedcd83bae08a3172f0242a570177366202a
Parent: d1e6f3f509
Structural diff unavailable

These commits were pushed via plain git push, so no pre-parsed schemas are available. Install git-remote-cospan and re-push via panproto:// to see scope-level changes, breaking change detection, and semantic diffs.

brew install panproto/tap/git-remote-cospan
24 files changed +88 -1076
@@ -1,52 +1,2 @@
1-use chrono::{DateTime, Utc};
2-use sqlx::PgPool;
3-
4-#[derive(Debug, sqlx::FromRow, serde::Serialize)]
5-#[serde(rename_all = "camelCase")]
6-pub struct ActorProfileRow {
7-    pub did: String,
8-    pub bluesky: String,
9-    pub display_name: Option<String>,
10-    pub description: Option<String>,
11-    pub avatar_cid: Option<String>,
12-    pub indexed_at: DateTime<Utc>,
13-}
14-
15-pub async fn upsert(pool: &PgPool, row: &ActorProfileRow) -> Result<(), sqlx::Error> {
16-    sqlx::query(
17-        "INSERT INTO actor_profiles (did, bluesky, display_name, description, avatar_cid) \
18-         VALUES ($1, $2, $3, $4, $5) \
19-         ON CONFLICT (did) DO UPDATE SET \
20-           bluesky = EXCLUDED.bluesky, \
21-           display_name = EXCLUDED.display_name, \
22-           description = EXCLUDED.description, \
23-           avatar_cid = EXCLUDED.avatar_cid, \
24-           indexed_at = NOW()",
25-    )
26-    .bind(&row.did)
27-    .bind(&row.bluesky)
28-    .bind(&row.display_name)
29-    .bind(&row.description)
30-    .bind(&row.avatar_cid)
31-    .execute(pool)
32-    .await?;
33-    Ok(())
34-}
35-
36-pub async fn delete(pool: &PgPool, did: &str) -> Result<(), sqlx::Error> {
37-    sqlx::query("DELETE FROM actor_profiles WHERE did = $1")
38-        .bind(did)
39-        .execute(pool)
40-        .await?;
41-    Ok(())
42-}
43-
44-pub async fn get(pool: &PgPool, did: &str) -> Result<Option<ActorProfileRow>, sqlx::Error> {
45-    sqlx::query_as::<_, ActorProfileRow>(
46-        "SELECT did, bluesky, display_name, description, avatar_cid, indexed_at \
47-         FROM actor_profiles WHERE did = $1",
48-    )
49-    .bind(did)
50-    .fetch_optional(pool)
51-    .await
52-}
1+pub use super::generated::types::ActorProfileRow;
2+pub use super::generated::crud::actor_profiles::{delete, get, list, upsert};
@@ -1,48 +1,9 @@
1+pub use super::generated::crud::collaborators::{delete, get, list, upsert};
2+pub use super::generated::types::CollaboratorRow;
3+
14 use chrono::{DateTime, Utc};
25 use sqlx::PgPool;
36 
4-#[derive(Debug, sqlx::FromRow, serde::Serialize)]
5-#[serde(rename_all = "camelCase")]
6-pub struct CollaboratorRow {
7-    pub did: String,
8-    pub rkey: String,
9-    pub repo_did: String,
10-    pub repo_name: String,
11-    pub member_did: String,
12-    pub role: String,
13-    pub created_at: DateTime<Utc>,
14-    pub indexed_at: DateTime<Utc>,
15-}
16-
17-pub async fn upsert(pool: &PgPool, row: &CollaboratorRow) -> Result<(), sqlx::Error> {
18-    sqlx::query(
19-        "INSERT INTO collaborators (did, rkey, repo_did, repo_name, member_did, role, created_at) \
20-         VALUES ($1, $2, $3, $4, $5, $6, $7) \
21-         ON CONFLICT (did, rkey) DO UPDATE SET \
22-           role = EXCLUDED.role, \
23-           indexed_at = NOW()",
24-    )
25-    .bind(&row.did)
26-    .bind(&row.rkey)
27-    .bind(&row.repo_did)
28-    .bind(&row.repo_name)
29-    .bind(&row.member_did)
30-    .bind(&row.role)
31-    .bind(row.created_at)
32-    .execute(pool)
33-    .await?;
34-    Ok(())
35-}
36-
37-pub async fn delete(pool: &PgPool, did: &str, rkey: &str) -> Result<(), sqlx::Error> {
38-    sqlx::query("DELETE FROM collaborators WHERE did = $1 AND rkey = $2")
39-        .bind(did)
40-        .bind(rkey)
41-        .execute(pool)
42-        .await?;
43-    Ok(())
44-}
45-
467 pub async fn list_for_repo(
478     pool: &PgPool,
489     repo_did: &str,
@@ -1,61 +1,9 @@
1+pub use super::generated::crud::dependencies::{delete, get, list, upsert};
2+pub use super::generated::types::DependencyRow;
3+
14 use chrono::{DateTime, Utc};
25 use sqlx::PgPool;
36 
4-#[derive(Debug, sqlx::FromRow, serde::Serialize)]
5-#[serde(rename_all = "camelCase")]
6-pub struct DependencyRow {
7-    pub did: String,
8-    pub rkey: String,
9-    pub source_repo_did: String,
10-    pub source_repo_name: String,
11-    pub target_repo_did: String,
12-    pub target_repo_name: String,
13-    pub morphism_id: String,
14-    pub source_protocol: Option<String>,
15-    pub target_protocol: Option<String>,
16-    pub description: Option<String>,
17-    pub created_at: DateTime<Utc>,
18-    pub indexed_at: DateTime<Utc>,
19-}
20-
21-pub async fn upsert(pool: &PgPool, row: &DependencyRow) -> Result<(), sqlx::Error> {
22-    sqlx::query(
23-        "INSERT INTO dependencies (did, rkey, source_repo_did, source_repo_name, \
24-              target_repo_did, target_repo_name, morphism_id, source_protocol, target_protocol, \
25-              description, created_at) \
26-         VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) \
27-         ON CONFLICT (did, rkey) DO UPDATE SET \
28-           morphism_id = EXCLUDED.morphism_id, \
29-           source_protocol = EXCLUDED.source_protocol, \
30-           target_protocol = EXCLUDED.target_protocol, \
31-           description = EXCLUDED.description, \
32-           indexed_at = NOW()",
33-    )
34-    .bind(&row.did)
35-    .bind(&row.rkey)
36-    .bind(&row.source_repo_did)
37-    .bind(&row.source_repo_name)
38-    .bind(&row.target_repo_did)
39-    .bind(&row.target_repo_name)
40-    .bind(&row.morphism_id)
41-    .bind(&row.source_protocol)
42-    .bind(&row.target_protocol)
43-    .bind(&row.description)
44-    .bind(row.created_at)
45-    .execute(pool)
46-    .await?;
47-    Ok(())
48-}
49-
50-pub async fn delete(pool: &PgPool, did: &str, rkey: &str) -> Result<(), sqlx::Error> {
51-    sqlx::query("DELETE FROM dependencies WHERE did = $1 AND rkey = $2")
52-        .bind(did)
53-        .bind(rkey)
54-        .execute(pool)
55-        .await?;
56-    Ok(())
57-}
58-
597 pub async fn list_for_repo(
608     pool: &PgPool,
619     source_did: &str,
@@ -1,53 +1,9 @@
1+pub use super::generated::crud::follows::{delete, get, list, upsert};
2+pub use super::generated::types::FollowRow;
3+
14 use chrono::{DateTime, Utc};
25 use sqlx::PgPool;
36 
4-#[derive(Debug, sqlx::FromRow, serde::Serialize)]
5-#[serde(rename_all = "camelCase")]
6-pub struct FollowRow {
7-    pub did: String,
8-    pub rkey: String,
9-    pub subject: String,
10-    pub created_at: DateTime<Utc>,
11-    pub indexed_at: DateTime<Utc>,
12-}
13-
14-pub async fn upsert(pool: &PgPool, row: &FollowRow) -> Result<(), sqlx::Error> {
15-    sqlx::query(
16-        "INSERT INTO follows (did, rkey, subject, created_at) \
17-         VALUES ($1, $2, $3, $4) \
18-         ON CONFLICT (did, rkey) DO UPDATE SET \
19-           subject = EXCLUDED.subject, \
20-           indexed_at = NOW()",
21-    )
22-    .bind(&row.did)
23-    .bind(&row.rkey)
24-    .bind(&row.subject)
25-    .bind(row.created_at)
26-    .execute(pool)
27-    .await?;
28-    Ok(())
29-}
30-
31-pub async fn delete(pool: &PgPool, did: &str, rkey: &str) -> Result<(), sqlx::Error> {
32-    sqlx::query("DELETE FROM follows WHERE did = $1 AND rkey = $2")
33-        .bind(did)
34-        .bind(rkey)
35-        .execute(pool)
36-        .await?;
37-    Ok(())
38-}
39-
40-pub async fn get(pool: &PgPool, did: &str, rkey: &str) -> Result<Option<FollowRow>, sqlx::Error> {
41-    sqlx::query_as::<_, FollowRow>(
42-        "SELECT did, rkey, subject, created_at, indexed_at \
43-         FROM follows WHERE did = $1 AND rkey = $2",
44-    )
45-    .bind(did)
46-    .bind(rkey)
47-    .fetch_optional(pool)
48-    .await
49-}
50-
517 pub async fn list_following(
528     pool: &PgPool,
539     did: &str,
@@ -1,52 +1,9 @@
1+pub use super::generated::crud::issues::{delete, list, upsert};
2+pub use super::generated::types::IssueRow;
3+
14 use chrono::{DateTime, Utc};
25 use sqlx::PgPool;
36 
4-#[derive(Debug, sqlx::FromRow, serde::Serialize)]
5-#[serde(rename_all = "camelCase")]
6-pub struct IssueRow {
7-    pub did: String,
8-    pub rkey: String,
9-    pub repo_did: String,
10-    pub repo_name: String,
11-    pub title: String,
12-    pub body: Option<String>,
13-    pub state: String,
14-    pub comment_count: i32,
15-    pub created_at: DateTime<Utc>,
16-    pub indexed_at: DateTime<Utc>,
17-}
18-
19-pub async fn upsert(pool: &PgPool, row: &IssueRow) -> Result<(), sqlx::Error> {
20-    sqlx::query(
21-        "INSERT INTO issues (did, rkey, repo_did, repo_name, title, body, state, created_at) \
22-         VALUES ($1, $2, $3, $4, $5, $6, $7, $8) \
23-         ON CONFLICT (did, rkey) DO UPDATE SET \
24-           title = EXCLUDED.title, \
25-           body = EXCLUDED.body, \
26-           indexed_at = NOW()",
27-    )
28-    .bind(&row.did)
29-    .bind(&row.rkey)
30-    .bind(&row.repo_did)
31-    .bind(&row.repo_name)
32-    .bind(&row.title)
33-    .bind(&row.body)
34-    .bind(&row.state)
35-    .bind(row.created_at)
36-    .execute(pool)
37-    .await?;
38-    Ok(())
39-}
40-
41-pub async fn delete(pool: &PgPool, did: &str, rkey: &str) -> Result<(), sqlx::Error> {
42-    sqlx::query("DELETE FROM issues WHERE did = $1 AND rkey = $2")
43-        .bind(did)
44-        .bind(rkey)
45-        .execute(pool)
46-        .await?;
47-    Ok(())
48-}
49-
507 /// Get an issue by repo owner DID, repo name, and issue rkey.
518 pub async fn get(
529     pool: &PgPool,
cospan · schematic version control on atproto built on AT Protocol