fix: enable production PostgreSQL persistence - #142
Conversation
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
| "INSERT INTO responses \ | ||
| (id, conversation_id, previous_response_id, history_item_ids, metadata, created_at) \ | ||
| VALUES (?, ?, ?, ?, ?, ?) RETURNING *", | ||
| VALUES ($1, $2, $3, $4, $5, $6) RETURNING *", |
There was a problem hiding this comment.
this works for both postgres and sqlite, postgres rejects "?"
maralbahari
left a comment
There was a problem hiding this comment.
Thanks for the work. I left some inline comments
| .map_err(|source| { | ||
| error!(error = ?source, "failed to persist response"); | ||
| crate::executor::error::ExecutorError::Persistence(Box::new(source)) | ||
| }) |
There was a problem hiding this comment.
nit: this line is too long, can import on top of the file use crate::executor::error{ExecutorError}
| } | ||
|
|
||
| fn is_postgres_url(url: &str) -> bool { | ||
| url.starts_with("postgres://") || url.starts_with("postgresql://") |
There was a problem hiding this comment.
Parse the database URL once instead of detecting backends with starts_with.
SQLx parses the URL through url::Url, which normalizes URI schemes, while these checks are case-sensitive. A valid POSTGRESQL://... connection succeeds but bypasses every POSTGRES_* setting and after_connect, leaving statement and lock timeouts unset. SQLite has the same classification problem. The redactor also misses case variants. Introduce a validated DatabaseBackend parsed from Url::scheme() and reuse it for configuration, pool construction, diagnostics, and redaction.
| let migration_result = sqlx::migrate!("./migrations") | ||
| .run(&mut *connection) | ||
| .await | ||
| .map_err(|error| sqlx::Error::Configuration(error.to_string().into())); |
There was a problem hiding this comment.
Converting MigrateError to error.to_string() and wrapping it as sqlx::Error::Configuration discards the source chain and means the new sqlx::Error::Migrate classification can never handle actual migrator failures. Preserve it with sqlx::Error::Migrate(Box::new(error)), or use a project error variant with #[source]
Summary
INTEGERtoBIGINTcompatibility upgrade, while supporting read-only supervisor-managed schema validationThis is the PostgreSQL persistence slice of #102.
Closes #103.
Refs #102.
Test Plan
cargo fmt -- --checkcargo clippy --all-targets -- -D warningscargo testuvx pre-commit run --all-filesTEST_POSTGRES_URL=... cargo test -p agentic-server-core --lib postgres_integer_widening_upgrade_preserves_existing_state -- --ignored --nocaptureTEST_POSTGRES_URL=... cargo test -p agentic-server-core --test postgres_storage_integration -- --ignored --nocaptureuv run --with-requirements docs/requirements.txt mkdocs build --strict(reaches the pre-existing brokendocs/design/claude-code-integration.mdlink toROADMAP.md)