Skip to content
Open
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
17 changes: 17 additions & 0 deletions nexus/db-queries/src/db/datastore/silo_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::db::model::to_db_typed_uuid;
use crate::db::pagination::paginated;
use async_bb8_diesel::AsyncRunQueryDsl;
use chrono::DateTime;
use chrono::Timelike;
use chrono::Utc;
use diesel::prelude::*;
use nexus_db_errors::ErrorHandler;
Expand All @@ -36,6 +37,16 @@ use omicron_uuid_kinds::SiloGroupUuid;
use omicron_uuid_kinds::SiloUserUuid;
use uuid::Uuid;

/// Round a DateTime to microsecond precision to match database TIMESTAMPTZ
/// precision. This ensures that timestamps created in-memory (with nanosecond
/// precision) match timestamps retrieved from the database (which only stores
/// microsecond precision).
fn round_to_micros(dt: DateTime<Utc>) -> DateTime<Utc> {
let nanos = dt.timestamp_subsec_nanos();
let micros = (nanos / 1000) * 1000;
dt.with_nanosecond(micros).unwrap()
}

/// The datastore crate's SiloGroup is intended to provide type safety above the
/// database model, as the same database model is used to store semantically
/// different group types. Higher level parts of Nexus should use this type
Expand Down Expand Up @@ -193,6 +204,8 @@ impl From<SiloGroupApiOnly> for views::Group {
// TODO the use of external_id as display_name is temporary
display_name: u.external_id,
silo_id: u.silo_id,
time_created: round_to_micros(u.time_created),
time_modified: round_to_micros(u.time_modified),
}
}
}
Expand Down Expand Up @@ -252,6 +265,8 @@ impl From<SiloGroupJit> for views::Group {
// TODO the use of external_id as display_name is temporary
display_name: u.external_id,
silo_id: u.silo_id,
time_created: round_to_micros(u.time_created),
time_modified: round_to_micros(u.time_modified),
}
}
}
Expand Down Expand Up @@ -319,6 +334,8 @@ impl From<SiloGroupScim> for views::Group {
// TODO the use of display name as display_name is temporary
display_name: u.display_name,
silo_id: u.silo_id,
time_created: round_to_micros(u.time_created),
time_modified: round_to_micros(u.time_modified),
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions nexus/db-queries/src/db/datastore/silo_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::db::pagination::paginated;
use crate::db::update_and_check::UpdateAndCheck;
use async_bb8_diesel::AsyncRunQueryDsl;
use chrono::DateTime;
use chrono::Timelike;
use chrono::Utc;
use diesel::prelude::*;
use nexus_db_errors::ErrorHandler;
Expand All @@ -43,6 +44,16 @@ use omicron_uuid_kinds::GenericUuid;
use omicron_uuid_kinds::SiloUserUuid;
use uuid::Uuid;

/// Round a DateTime to microsecond precision to match database TIMESTAMPTZ
/// precision. This ensures that timestamps created in-memory (with nanosecond
/// precision) match timestamps retrieved from the database (which only stores
/// microsecond precision).
fn round_to_micros(dt: DateTime<Utc>) -> DateTime<Utc> {
let nanos = dt.timestamp_subsec_nanos();
let micros = (nanos / 1000) * 1000;
dt.with_nanosecond(micros).unwrap()
}

/// The datastore crate's SiloUser is intended to provide type safety above the
/// database model, as the same database model is used to store semantically
/// different user types. Higher level parts of Nexus should use this type
Expand Down Expand Up @@ -234,6 +245,8 @@ impl From<SiloUserApiOnly> for views::User {
// TODO the use of external_id as display_name is temporary
display_name: u.external_id,
silo_id: u.silo_id,
time_created: round_to_micros(u.time_created),
time_modified: round_to_micros(u.time_modified),
}
}
}
Expand Down Expand Up @@ -294,6 +307,8 @@ impl From<SiloUserJit> for views::User {
// TODO the use of external_id as display_name is temporary
display_name: u.external_id,
silo_id: u.silo_id,
time_created: round_to_micros(u.time_created),
time_modified: round_to_micros(u.time_modified),
}
}
}
Expand Down Expand Up @@ -365,6 +380,8 @@ impl From<SiloUserScim> for views::User {
// TODO the use of user_name as display_name is temporary
display_name: u.user_name,
silo_id: u.silo_id,
time_created: round_to_micros(u.time_created),
time_modified: round_to_micros(u.time_modified),
}
}
}
Expand Down
Loading
Loading