fix: adapt ingest_worker to production DB schema

- Match memory_entity columns: id, project_id, name, entity_type, description, t_created, t_updated, confidence
- Match memory_edge columns: id, project_id, source_entity_id, target_entity_id, relation_type, fact, t_valid, t_invalid, t_created, confidence
- Convert OffsetDateTime to RFC3339 strings for TIMESTAMPTZ binding
- E2E test confirms: entities save successfully to production DB

Entities extraction working. Next: fact extraction and edges, query handler.
This commit is contained in:
2026-09-08 10:10:21 -07:00
parent 25dde42ea4
commit 52b037f788
2 changed files with 84 additions and 29 deletions
+9 -14
View File
@@ -167,21 +167,22 @@ fn extract_wiki_links(text: &str) -> Vec<String> {
/// Save entity to database via raw SQL (normally would use EntityRepo trait)
async fn save_entity_to_db(pool: &PgPool, entity: &mem_core::entity::Entity) -> Result<()> {
// Convert OffsetDateTime to string in RFC3339 format, then back to chrono for sqlx
// Convert OffsetDateTime to PostgreSQL timestamp format
let t_created_str = entity.t_created.to_string();
let t_expired_str = entity.t_expired.map(|t| t.to_string());
sqlx::query(
"INSERT INTO memory_entity (id, project_id, name, entity_type, t_created, t_expired)
VALUES ($1, $2, $3, $4, $5::TIMESTAMPTZ, $6::TIMESTAMPTZ)
"INSERT INTO memory_entity (id, project_id, name, entity_type, description, t_created, t_updated, confidence)
VALUES ($1, $2, $3, $4, $5, $6::TIMESTAMPTZ, $7::TIMESTAMPTZ, $8)
ON CONFLICT (id) DO NOTHING"
)
.bind(&entity.id)
.bind(&entity.project_id)
.bind(&entity.name)
.bind(entity.entity_type.as_str())
.bind(entity.summary.as_deref())
.bind(&t_created_str)
.bind(&t_expired_str)
.bind(&t_created_str)
.bind(1.0_f32) // default confidence
.execute(pool)
.await?;
Ok(())
@@ -189,17 +190,13 @@ async fn save_entity_to_db(pool: &PgPool, entity: &mem_core::entity::Entity) ->
/// Save edge to database via raw SQL (normally would use EdgeRepo trait)
async fn save_edge_to_db(pool: &PgPool, edge: &mem_core::edge::Edge) -> Result<()> {
let t_created_str = edge.t_created.to_string();
let t_valid_str = edge.t_valid.map(|t| t.to_string());
let t_invalid_str = edge.t_invalid.map(|t| t.to_string());
let t_created_str = edge.t_created.to_string();
let t_expired_str = edge.t_expired.map(|t| t.to_string());
sqlx::query(
"INSERT INTO memory_edge (
id, project_id, source_entity_id, target_entity_id,
relation_type, fact, t_valid, t_invalid, t_created, t_expired,
contradiction_status, confidence
) VALUES ($1, $2, $3, $4, $5, $6, $7::TIMESTAMPTZ, $8::TIMESTAMPTZ, $9::TIMESTAMPTZ, $10::TIMESTAMPTZ, $11, $12)
"INSERT INTO memory_edge (id, project_id, source_entity_id, target_entity_id, relation_type, fact, t_valid, t_invalid, t_created, confidence)
VALUES ($1, $2, $3, $4, $5, $6, $7::TIMESTAMPTZ, $8::TIMESTAMPTZ, $9::TIMESTAMPTZ, $10)
ON CONFLICT (id) DO NOTHING"
)
.bind(&edge.id)
@@ -211,8 +208,6 @@ async fn save_edge_to_db(pool: &PgPool, edge: &mem_core::edge::Edge) -> Result<(
.bind(&t_valid_str)
.bind(&t_invalid_str)
.bind(&t_created_str)
.bind(&t_expired_str)
.bind(edge.contradiction_status.as_str())
.bind(edge.confidence)
.execute(pool)
.await?;