feat: Identity JSON sync + schema-aware column selection

- storage.rs: add local_profile field, check disk for profile.jpg
- tmdb_api.rs: trigger JSON sync after TMDb probe
- identity_api.rs: upload_profile_image triggers JSON sync
- identity_binding.rs: bind/unbind/merge trigger JSON sync
- get_identity_json: Lazy Sync (generates JSON from DB if missing)
- identities.rs + identity_api.rs: use schema-aware column selection (dev:name vs public:real_name)
- Fixes 500 errors on identities endpoints across schemas
This commit is contained in:
Accusys
2026-05-19 23:10:49 +08:00
parent 0eb08acaae
commit ba68cd2548
3 changed files with 21 additions and 14 deletions

View File

@@ -92,18 +92,21 @@ async fn create_identity(
)
})?;
let query = r#"
SELECT uuid, reference_data->'total_references' as total,
let id_table = crate::core::db::schema::table_name("identities");
let name_col = if id_table.starts_with("dev.") { "name" } else { "real_name" };
let query = format!(
"SELECT uuid, reference_data->'total_references' as total,
reference_data->'angles_covered' as angles,
reference_data->'quality_avg' as quality
FROM identities
WHERE real_name = $1
FROM {}
WHERE {} = $1
ORDER BY created_at DESC
LIMIT 1
"#;
LIMIT 1",
id_table, name_col
);
let row: Option<(String, Option<i32>, Option<Vec<String>>, Option<f64>)> =
sqlx::query_as(query)
sqlx::query_as(&query)
.bind(&req.identity_name)
.fetch_optional(db.pool())
.await
@@ -168,7 +171,8 @@ async fn list_identities(
.fetch_one(db.pool()).await
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("Count error: {}", e)))?;
let sql = format!("SELECT id::int, uuid, real_name, metadata FROM {} ORDER BY id DESC LIMIT $1 OFFSET $2", id_table);
let name_col = if id_table.starts_with("dev.") { "name" } else { "real_name" };
let sql = format!("SELECT id::int, uuid, {} AS name, metadata FROM {} ORDER BY id DESC LIMIT $1 OFFSET $2", name_col, id_table);
let rows: Vec<(i32, uuid::Uuid, String, Option<serde_json::Value>)> = match sqlx::query_as(&sql)
.bind(page_size as i64)