Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 51 additions & 104 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ hmac = "0.13.0"
sha2 = "0.11.1"
hex = "0.4.3"
regex = "1.13.1"
chrono = { version = "0.4", default-features = false, features = ["clock", "std"] }
jiff = { version = "0.2", default-features = false, features = ["std"] }
subtle = "2.6"
sqlx = { version = "0.9.0", default-features = false, features = ["runtime-tokio", "tls-rustls", "sqlite", "postgres", "macros", "migrate"] }
32 changes: 29 additions & 3 deletions src/db.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
use anyhow::{Context, Result};
use chrono::Utc;
use jiff::{Timestamp, tz::Offset};
use serde::{Deserialize, Serialize};
use sqlx::{FromRow, PgPool, SqlitePool};
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use tracing::info;

/// Current UTC time as RFC 3339 with a `+00:00` offset, the format every stored
/// `created_at` has; rows sort by this text.
pub fn now_rfc3339() -> String {
Timestamp::now()
.display_with_offset(Offset::UTC)
.to_string()
}

#[derive(Clone)]
pub enum DbPool {
Sqlite(SqlitePool),
Expand Down Expand Up @@ -239,7 +247,7 @@ impl DbPool {

/// Records an executed review run and returns its primary key.
pub async fn record_review(&self, rec: &NewReviewRecord<'_>) -> Result<i64> {
let now = Utc::now().to_rfc3339();
let now = now_rfc3339();
let sql = r#"
INSERT INTO reviews (repo, pr_number, title, author, status, provider_used,
pass1_candidates, pass2_filtered, verified_findings,
Expand Down Expand Up @@ -313,7 +321,7 @@ impl DbPool {
feedback_type: &str,
reason: Option<&str>,
) -> Result<i64> {
let now = Utc::now().to_rfc3339();
let now = now_rfc3339();
let sql = r#"
INSERT INTO findings_feedback (repo, file_path, issue_title, feedback_type, reason, created_at)
VALUES ($1, $2, $3, $4, $5, $6)
Expand Down Expand Up @@ -419,6 +427,24 @@ impl DbPool {
mod tests {
use super::*;

#[test]
fn now_rfc3339_matches_stored_format() {
let now = now_rfc3339();
// e.g. 2026-11-17T11:02:03.123456789+00:00, as chrono wrote it before.
let (stamp, offset) = now.split_at(now.len() - 6);
assert_eq!(offset, "+00:00", "{now}");
let (date, time) = stamp.split_once('T').expect("date and time");
assert_eq!(date.len(), 10, "{now}");
assert_eq!(
&time[..8].replace(|c: char| c.is_ascii_digit(), "0"),
"00:00:00",
"{now}"
);
assert!(time.len() == 8 || time.as_bytes()[8] == b'.', "{now}");
// Text order must stay time order next to rows written earlier.
assert!(now.as_str() > "2026-01-01T00:00:00+00:00");
}

#[tokio::test]
async fn test_sqlite_in_memory_lifecycle() {
let db = DbPool::connect("sqlite::memory:")
Expand Down
2 changes: 1 addition & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ async fn spawn_review_job(
pass2_verified: 0,
duration_secs: 0,
provider_used: provider_hint,
created_at: chrono::Utc::now().to_rfc3339(),
created_at: crate::db::now_rfc3339(),
summary: if cur_publish {
"Two-pass review executing (live publishing enabled).".to_string()
} else {
Expand Down
Loading