Skip to content

Commit

Permalink
Paginator, regression tests, multi-column
Browse files Browse the repository at this point in the history
  • Loading branch information
smklein committed Jun 26, 2024
1 parent 2c5a1a6 commit e97a58a
Show file tree
Hide file tree
Showing 3 changed files with 237 additions and 87 deletions.
8 changes: 4 additions & 4 deletions nexus/db-model/src/saga_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl From<&SecId> for Uuid {
/// This exists because Omicron cannot implement foreign traits
/// for foreign types.
#[derive(
AsExpression, Copy, Clone, Debug, FromSqlRow, PartialEq, PartialOrd,
AsExpression, Copy, Clone, Debug, FromSqlRow, PartialEq, PartialOrd, Ord, Eq,
)]
#[diesel(sql_type = sql_types::Uuid)]
pub struct SagaId(pub steno::SagaId);
Expand Down Expand Up @@ -110,7 +110,7 @@ where
/// This exists because Omicron cannot implement foreign traits
/// for foreign types.
#[derive(
AsExpression, Copy, Clone, Debug, FromSqlRow, PartialEq, PartialOrd,
AsExpression, Copy, Clone, Debug, FromSqlRow, PartialEq, PartialOrd, Ord, Eq,
)]
#[diesel(sql_type = sql_types::BigInt)]
pub struct SagaNodeId(pub steno::SagaNodeId);
Expand Down Expand Up @@ -181,7 +181,7 @@ impl FromSql<SagaCachedStateEnum, Pg> for SagaCachedState {
}

/// Represents a row in the "Saga" table
#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
#[derive(Queryable, Insertable, Clone, Debug, Selectable, PartialEq)]
#[diesel(table_name = saga)]
pub struct Saga {
pub id: SagaId,
Expand Down Expand Up @@ -222,7 +222,7 @@ impl Saga {
}

/// Represents a row in the "SagaNodeEvent" table
#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
#[derive(Queryable, Insertable, Clone, Debug, Selectable, PartialEq)]
#[diesel(table_name = saga_node_event)]
pub struct SagaNodeEvent {
pub saga_id: SagaId,
Expand Down
54 changes: 0 additions & 54 deletions nexus/db-queries/src/db/datastore/saga.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ use crate::db;
use crate::db::error::public_error_from_diesel;
use crate::db::error::ErrorHandler;
use crate::db::model::Generation;
use crate::db::pagination::paginated;
use crate::db::update_and_check::UpdateAndCheck;
use crate::db::update_and_check::UpdateStatus;
use async_bb8_diesel::AsyncRunQueryDsl;
use diesel::prelude::*;
use omicron_common::api::external::DataPageParams;
use omicron_common::api::external::Error;
use omicron_common::api::external::ListResultVec;
use omicron_common::api::external::LookupType;
use omicron_common::api::external::ResourceType;
use uuid::Uuid;

impl DataStore {
pub async fn saga_create(
Expand Down Expand Up @@ -103,54 +99,4 @@ impl DataStore {
)),
}
}

pub async fn saga_list_unfinished_by_id(
&self,
sec_id: &db::SecId,
pagparams: &DataPageParams<'_, Uuid>,
) -> ListResultVec<db::saga_types::Saga> {
use db::schema::saga::dsl;
paginated(dsl::saga, dsl::id, &pagparams)
.filter(dsl::saga_state.ne(db::saga_types::SagaCachedState(
steno::SagaCachedState::Done,
)))
.filter(dsl::current_sec.eq(*sec_id))
.load_async(&*self.pool_connection_unauthorized().await?)
.await
.map_err(|e| {
public_error_from_diesel(
e,
ErrorHandler::NotFoundByLookup(
ResourceType::SagaDbg,
LookupType::ById(sec_id.0),
),
)
})
}

pub async fn saga_node_event_list_by_id(
&self,
id: db::saga_types::SagaId,
pagparams: &DataPageParams<'_, db::saga_types::SagaNodeId>,
) -> ListResultVec<steno::SagaNodeEvent> {
use db::schema::saga_node_event::dsl;
paginated(dsl::saga_node_event, dsl::node_id, &pagparams)
.filter(dsl::saga_id.eq(id))
.load_async::<db::saga_types::SagaNodeEvent>(
&*self.pool_connection_unauthorized().await?,
)
.await
.map_err(|e| {
public_error_from_diesel(
e,
ErrorHandler::NotFoundByLookup(
ResourceType::SagaDbg,
LookupType::ById(id.0 .0),
),
)
})?
.into_iter()
.map(|db_event| steno::SagaNodeEvent::try_from(db_event))
.collect::<Result<_, Error>>()
}
}
Loading

0 comments on commit e97a58a

Please sign in to comment.