Skip to content

Commit

Permalink
Rename certificatecolumn and record field to pending_certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
sfauvel committed Nov 27, 2024
1 parent 6bad9ab commit 278ef1d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions mithril-aggregator/src/database/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,12 +864,12 @@ insert into signed_entity_type (signed_entity_type_id, name)
r#"
create table new_pending_certificate (
epoch integer not null,
certificate text not null,
pending_certificate text not null,
created_at text not null,
primary key (epoch)
);
create table if not exists pending_certificate (key_hash text primary key, key json not null, value json not null);
insert into new_pending_certificate (epoch, certificate, created_at)
insert into new_pending_certificate (epoch, pending_certificate, created_at)
select
json_extract(pending_certificate.value, '$.epoch') as epoch,
pending_certificate.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ pub struct SavePendingCertificateRecordQuery {
impl SavePendingCertificateRecordQuery {
pub fn save(pending_certificate_record: CertificatePendingRecord) -> Self {
let condition = WhereCondition::new(
"(epoch, certificate, created_at) values (?*, ?*, ?*)",
"(epoch, pending_certificate, created_at) values (?*, ?*, ?*)",
vec![
Value::Integer(*pending_certificate_record.epoch as i64),
Value::String(pending_certificate_record.certificate),
Value::String(pending_certificate_record.pending_certificate),
Value::String(Utc::now().to_rfc3339()),
],
);
Expand Down
14 changes: 9 additions & 5 deletions mithril-aggregator/src/database/record/certificate_pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct CertificatePendingRecord {
pub epoch: Epoch,

/// Pending certificate serialization as json
pub certificate: String,
pub pending_certificate: String,

/// Date and time when the pending certificate was created
pub created_at: DateTime<Utc>,
Expand All @@ -35,7 +35,7 @@ impl SqLiteEntity for CertificatePendingRecord {
let created_at = &row.read::<&str, _>(2);

let record = Self {
certificate: pending_certificate_json.to_string(),
pending_certificate: pending_certificate_json.to_string(),
created_at: DateTime::parse_from_rfc3339(created_at)
.map_err(|e| {
HydrationError::InvalidData(format!(
Expand All @@ -57,7 +57,11 @@ impl SqLiteEntity for CertificatePendingRecord {
let mut projection = Projection::default();

projection.add_field("epoch", "{:pending_certificate:}.epoch", "integer");
projection.add_field("certificate", "{:pending_certificate:}.certificate", "text");
projection.add_field(
"pending_certificate",
"{:pending_certificate:}.pending_certificate",
"text",
);
projection.add_field("created_at", "{:pending_certificate:}.created_at", "text");

projection
Expand All @@ -70,7 +74,7 @@ impl TryFrom<CertificatePending> for CertificatePendingRecord {
fn try_from(value: CertificatePending) -> Result<Self, Self::Error> {
let record = Self {
epoch: value.epoch,
certificate: serde_json::to_string(&value)?,
pending_certificate: serde_json::to_string(&value)?,
created_at: Utc::now(),
};
Ok(record)
Expand All @@ -80,7 +84,7 @@ impl TryFrom<CertificatePending> for CertificatePendingRecord {
impl TryFrom<CertificatePendingRecord> for CertificatePending {
type Error = StdError;
fn try_from(record: CertificatePendingRecord) -> Result<Self, Self::Error> {
let c: CertificatePending = serde_json::from_str(&record.certificate)?;
let c: CertificatePending = serde_json::from_str(&record.pending_certificate)?;
let pending_certificate = Self {
epoch: record.epoch,
signed_entity_type: c.signed_entity_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ impl CertificatePendingStorer for CertificatePendingRepository {
}

/// Save the given [CertificatePending].
async fn save(&self, certificate: CertificatePending) -> StdResult<()> {
async fn save(&self, pending_certificate: CertificatePending) -> StdResult<()> {
self.connection
.apply(SavePendingCertificateRecordQuery::save(
certificate.try_into()?,
pending_certificate.try_into()?,
))?;

Ok(())
Expand Down

0 comments on commit 278ef1d

Please sign in to comment.