From bf73a5c4c87722c96ffcc9b0df9f26ec97e7262a Mon Sep 17 00:00:00 2001 From: adrianwb Date: Wed, 30 Aug 2023 16:50:00 +0100 Subject: [PATCH] Some(changes) as suggested by Andrei + ran cargo fmt --- .../src/migrations/v1_02_00/sensor.rs | 7 +- server/service/src/sync/test/mod.rs | 14 +- .../sync/test/test_data/temperature_breach.rs | 161 +++++++++--------- .../test_data/temperature_breach_config.rs | 111 ++++++------ .../sync/test/test_data/temperature_log.rs | 112 ++++++------ server/service/src/sync/translations/mod.rs | 1 + .../sync/translations/temperature_breach.rs | 5 +- .../translations/temperature_breach_config.rs | 2 +- 8 files changed, 213 insertions(+), 200 deletions(-) diff --git a/server/repository/src/migrations/v1_02_00/sensor.rs b/server/repository/src/migrations/v1_02_00/sensor.rs index 73cab959b7..22a04167e3 100644 --- a/server/repository/src/migrations/v1_02_00/sensor.rs +++ b/server/repository/src/migrations/v1_02_00/sensor.rs @@ -54,8 +54,7 @@ pub(crate) fn migrate(connection: &StorageConnection) -> anyhow::Result<()> { "# )?; - #[cfg(feature = "postgres")] - { + if cfg!(feature = "postgres") { sql!( connection, r#" @@ -76,9 +75,7 @@ pub(crate) fn migrate(connection: &StorageConnection) -> anyhow::Result<()> { FOR EACH ROW EXECUTE PROCEDURE update_changelog(); "# )?; - } - #[cfg(not(feature = "postgres"))] - { + } else { sql!( connection, r#" diff --git a/server/service/src/sync/test/mod.rs b/server/service/src/sync/test/mod.rs index e67be0336c..19d935dd47 100644 --- a/server/service/src/sync/test/mod.rs +++ b/server/service/src/sync/test/mod.rs @@ -181,10 +181,20 @@ pub(crate) async fn check_records_against_database( check_record_by_id!(TemperatureLogRowRepository, con, record, "TemperatureLog"); } TemperatureBreach(record) => { - check_record_by_id!(TemperatureBreachRowRepository, con, record, "TemperatureBreach"); + check_record_by_id!( + TemperatureBreachRowRepository, + con, + record, + "TemperatureBreach" + ); } TemperatureBreachConfig(record) => { - check_record_by_id!(TemperatureBreachConfigRowRepository, con, record, "TemperatureBreachConfig"); + check_record_by_id!( + TemperatureBreachConfigRowRepository, + con, + record, + "TemperatureBreachConfig" + ); } Location(record) => { check_record_by_id!(LocationRowRepository, con, record, "Location"); diff --git a/server/service/src/sync/test/test_data/temperature_breach.rs b/server/service/src/sync/test/test_data/temperature_breach.rs index 1c7143c0e9..af37381ce0 100644 --- a/server/service/src/sync/test/test_data/temperature_breach.rs +++ b/server/service/src/sync/test/test_data/temperature_breach.rs @@ -1,79 +1,82 @@ -use crate::sync::translations::{temperature_breach::{LegacyTemperatureBreachRow, LegacyTemperatureBreachType}, LegacyTableName, PullUpsertRecord}; - -use chrono::{Duration, NaiveDate, NaiveTime}; -use repository::{TemperatureBreachRow, TemperatureBreachRowType}; -use serde_json::json; - -use super::{TestSyncPullRecord, TestSyncPushRecord}; - -const TEMPERATURE_BREACH_1: (&'static str, &'static str) = ( - "996812e0c33911eb9757779d39ae2dbd", - r#"{ - "ID": "996812e0c33911eb9757779d39ae2dbd", - "sensor_ID": "cf5812e0c33911eb9757779d39ae2dbd", - "location_ID": "", - "type": "COLD_CONSECUTIVE", - "threshold_minimum_temperature": -273.0, - "threshold_maximum_temperature": 2.0, - "threshold_duration": 3600, - "duration": 86400, - "acknowledged": false, - "store_ID": "store_a", - "start_date": "2023-07-01", - "start_time": 47046, - "end_date": "2023-07-02", - "end_time": 47046 - }"#, -); - -pub(crate) fn test_pull_upsert_records() -> Vec { - vec![TestSyncPullRecord::new_pull_upsert( - LegacyTableName::TEMPERATURE_BREACH, - TEMPERATURE_BREACH_1, - PullUpsertRecord::TemperatureBreach(TemperatureBreachRow { - id: TEMPERATURE_BREACH_1.0.to_string(), - store_id: Some("store_a".to_string()), - location_id: None, - r#type: TemperatureBreachRowType::ColdConsecutive, - duration: 86400, - acknowledged: false, - sensor_id: "cf5812e0c33911eb9757779d39ae2dbd".to_string(), - threshold_minimum: -273.0, - threshold_maximum: 2.0, - threshold_duration: 3600, - start_timestamp: NaiveDate::from_ymd_opt(2023, 7, 1) - .unwrap() - .and_hms_opt(0, 0, 0) - .unwrap() - + Duration::seconds(47046), - end_timestamp: NaiveDate::from_ymd_opt(2023, 7, 2) - .unwrap() - .and_hms_opt(0, 0, 0) - .unwrap() - + Duration::seconds(47046), - }), - )] -} - -pub(crate) fn test_push_records() -> Vec { - vec![TestSyncPushRecord { - table_name: LegacyTableName::TEMPERATURE_BREACH.to_string(), - record_id: TEMPERATURE_BREACH_1.0.to_string(), - push_data: json!(LegacyTemperatureBreachRow { - id: TEMPERATURE_BREACH_1.0.to_string(), - r#type: LegacyTemperatureBreachType::ColdConsecutive, - duration: 86400, - acknowledged: false, - sensor_id: "cf5812e0c33911eb9757779d39ae2dbd".to_string(), - store_id: Some("store_a".to_string()), - location_id: None, - threshold_minimum: -273.0, - threshold_maximum: 2.0, - threshold_duration: 3600, - start_date: NaiveDate::from_ymd_opt(2023, 7, 1).unwrap(), - start_time: NaiveTime::from_hms_opt(13, 4, 6).unwrap(), - end_date: NaiveDate::from_ymd_opt(2023, 7, 2).unwrap(), - end_time: NaiveTime::from_hms_opt(13, 4, 6).unwrap(), - }), - }] -} +use crate::sync::translations::{ + temperature_breach::{LegacyTemperatureBreachRow, LegacyTemperatureBreachType}, + LegacyTableName, PullUpsertRecord, +}; + +use chrono::{Duration, NaiveDate, NaiveTime}; +use repository::{TemperatureBreachRow, TemperatureBreachRowType}; +use serde_json::json; + +use super::{TestSyncPullRecord, TestSyncPushRecord}; + +const TEMPERATURE_BREACH_1: (&'static str, &'static str) = ( + "996812e0c33911eb9757779d39ae2dbd", + r#"{ + "ID": "996812e0c33911eb9757779d39ae2dbd", + "sensor_ID": "cf5812e0c33911eb9757779d39ae2dbd", + "location_ID": "", + "type": "COLD_CONSECUTIVE", + "threshold_minimum_temperature": -273.0, + "threshold_maximum_temperature": 2.0, + "threshold_duration": 3600, + "duration": 86400, + "acknowledged": false, + "store_ID": "store_a", + "start_date": "2023-07-01", + "start_time": 47046, + "end_date": "2023-07-02", + "end_time": 47046 + }"#, +); + +pub(crate) fn test_pull_upsert_records() -> Vec { + vec![TestSyncPullRecord::new_pull_upsert( + LegacyTableName::TEMPERATURE_BREACH, + TEMPERATURE_BREACH_1, + PullUpsertRecord::TemperatureBreach(TemperatureBreachRow { + id: TEMPERATURE_BREACH_1.0.to_string(), + store_id: Some("store_a".to_string()), + location_id: None, + r#type: TemperatureBreachRowType::ColdConsecutive, + duration: 86400, + acknowledged: false, + sensor_id: "cf5812e0c33911eb9757779d39ae2dbd".to_string(), + threshold_minimum: -273.0, + threshold_maximum: 2.0, + threshold_duration: 3600, + start_timestamp: NaiveDate::from_ymd_opt(2023, 7, 1) + .unwrap() + .and_hms_opt(0, 0, 0) + .unwrap() + + Duration::seconds(47046), + end_timestamp: NaiveDate::from_ymd_opt(2023, 7, 2) + .unwrap() + .and_hms_opt(0, 0, 0) + .unwrap() + + Duration::seconds(47046), + }), + )] +} + +pub(crate) fn test_push_records() -> Vec { + vec![TestSyncPushRecord { + table_name: LegacyTableName::TEMPERATURE_BREACH.to_string(), + record_id: TEMPERATURE_BREACH_1.0.to_string(), + push_data: json!(LegacyTemperatureBreachRow { + id: TEMPERATURE_BREACH_1.0.to_string(), + r#type: LegacyTemperatureBreachType::ColdConsecutive, + duration: 86400, + acknowledged: false, + sensor_id: "cf5812e0c33911eb9757779d39ae2dbd".to_string(), + store_id: Some("store_a".to_string()), + location_id: None, + threshold_minimum: -273.0, + threshold_maximum: 2.0, + threshold_duration: 3600, + start_date: NaiveDate::from_ymd_opt(2023, 7, 1).unwrap(), + start_time: NaiveTime::from_hms_opt(13, 4, 6).unwrap(), + end_date: NaiveDate::from_ymd_opt(2023, 7, 2).unwrap(), + end_time: NaiveTime::from_hms_opt(13, 4, 6).unwrap(), + }), + }] +} diff --git a/server/service/src/sync/test/test_data/temperature_breach_config.rs b/server/service/src/sync/test/test_data/temperature_breach_config.rs index 5d792e0ef5..43bf9ed9a4 100644 --- a/server/service/src/sync/test/test_data/temperature_breach_config.rs +++ b/server/service/src/sync/test/test_data/temperature_breach_config.rs @@ -1,54 +1,57 @@ -use crate::sync::translations::{temperature_breach::LegacyTemperatureBreachType, temperature_breach_config::LegacyTemperatureBreachConfigRow, LegacyTableName, PullUpsertRecord}; - -use repository::{TemperatureBreachConfigRow, TemperatureBreachRowType}; -use serde_json::json; - -use super::{TestSyncPullRecord, TestSyncPushRecord}; - -const TEMPERATURE_BREACH_CONFIG_1: (&'static str, &'static str) = ( - "997812e0c33911eb9757779d39ae2dbd", - r#"{ - "ID": "997812e0c33911eb9757779d39ae2dbd", - "type": "COLD_CONSECUTIVE", - "description": "Cold Consecutive below 2.0 for 1 hour", - "minimum_temperature": -273.0, - "maximum_temperature": 2.0, - "duration": 3600, - "is_active": true, - "store_ID": "store_a" - }"#, -); - -pub(crate) fn test_pull_upsert_records() -> Vec { - vec![TestSyncPullRecord::new_pull_upsert( - LegacyTableName::TEMPERATURE_BREACH_CONFIG, - TEMPERATURE_BREACH_CONFIG_1, - PullUpsertRecord::TemperatureBreachConfig(TemperatureBreachConfigRow { - id: TEMPERATURE_BREACH_CONFIG_1.0.to_string(), - store_id: Some("store_a".to_string()), - r#type: TemperatureBreachRowType::ColdConsecutive, - description: "Cold Consecutive below 2.0 for 1 hour".to_string(), - is_active: true, - minimum_temperature: -273.0, - maximum_temperature: 2.0, - duration: 3600, - }), - )] -} - -pub(crate) fn test_push_records() -> Vec { - vec![TestSyncPushRecord { - table_name: LegacyTableName::TEMPERATURE_BREACH_CONFIG.to_string(), - record_id: TEMPERATURE_BREACH_CONFIG_1.0.to_string(), - push_data: json!(LegacyTemperatureBreachConfigRow { - id: TEMPERATURE_BREACH_CONFIG_1.0.to_string(), - r#type: LegacyTemperatureBreachType::ColdConsecutive, - description: "Cold Consecutive below 2.0 for 1 hour".to_string(), - is_active: true, - store_id: Some("store_a".to_string()), - minimum_temperature: -273.0, - maximum_temperature: 2.0, - duration: 3600, - }), - }] -} +use crate::sync::translations::{ + temperature_breach::LegacyTemperatureBreachType, + temperature_breach_config::LegacyTemperatureBreachConfigRow, LegacyTableName, PullUpsertRecord, +}; + +use repository::{TemperatureBreachConfigRow, TemperatureBreachRowType}; +use serde_json::json; + +use super::{TestSyncPullRecord, TestSyncPushRecord}; + +const TEMPERATURE_BREACH_CONFIG_1: (&'static str, &'static str) = ( + "997812e0c33911eb9757779d39ae2dbd", + r#"{ + "ID": "997812e0c33911eb9757779d39ae2dbd", + "type": "COLD_CONSECUTIVE", + "description": "Cold Consecutive below 2.0 for 1 hour", + "minimum_temperature": -273.0, + "maximum_temperature": 2.0, + "duration": 3600, + "is_active": true, + "store_ID": "store_a" + }"#, +); + +pub(crate) fn test_pull_upsert_records() -> Vec { + vec![TestSyncPullRecord::new_pull_upsert( + LegacyTableName::TEMPERATURE_BREACH_CONFIG, + TEMPERATURE_BREACH_CONFIG_1, + PullUpsertRecord::TemperatureBreachConfig(TemperatureBreachConfigRow { + id: TEMPERATURE_BREACH_CONFIG_1.0.to_string(), + store_id: Some("store_a".to_string()), + r#type: TemperatureBreachRowType::ColdConsecutive, + description: "Cold Consecutive below 2.0 for 1 hour".to_string(), + is_active: true, + minimum_temperature: -273.0, + maximum_temperature: 2.0, + duration: 3600, + }), + )] +} + +pub(crate) fn test_push_records() -> Vec { + vec![TestSyncPushRecord { + table_name: LegacyTableName::TEMPERATURE_BREACH_CONFIG.to_string(), + record_id: TEMPERATURE_BREACH_CONFIG_1.0.to_string(), + push_data: json!(LegacyTemperatureBreachConfigRow { + id: TEMPERATURE_BREACH_CONFIG_1.0.to_string(), + r#type: LegacyTemperatureBreachType::ColdConsecutive, + description: "Cold Consecutive below 2.0 for 1 hour".to_string(), + is_active: true, + store_id: Some("store_a".to_string()), + minimum_temperature: -273.0, + maximum_temperature: 2.0, + duration: 3600, + }), + }] +} diff --git a/server/service/src/sync/test/test_data/temperature_log.rs b/server/service/src/sync/test/test_data/temperature_log.rs index 45c5b03ada..fe58722845 100644 --- a/server/service/src/sync/test/test_data/temperature_log.rs +++ b/server/service/src/sync/test/test_data/temperature_log.rs @@ -1,55 +1,57 @@ -use crate::sync::translations::{temperature_log::LegacyTemperatureLogRow, LegacyTableName, PullUpsertRecord}; - -use chrono::{Duration, NaiveDate, NaiveTime}; -use repository::TemperatureLogRow; -use serde_json::json; - -use super::{TestSyncPullRecord, TestSyncPushRecord}; - -const TEMPERATURE_LOG_1: (&'static str, &'static str) = ( - "995812e0c33911eb9757779d39ae2dbd", - r#"{ - "ID": "995812e0c33911eb9757779d39ae2dbd", - "sensor_ID": "cf5812e0c33911eb9757779d39ae2dbd", - "location_ID": "", - "temperature": 10.6, - "store_ID": "store_a", - "date": "2023-07-01", - "time": 47046 - }"#, -); - -pub(crate) fn test_pull_upsert_records() -> Vec { - vec![TestSyncPullRecord::new_pull_upsert( - LegacyTableName::TEMPERATURE_LOG, - TEMPERATURE_LOG_1, - PullUpsertRecord::TemperatureLog(TemperatureLogRow { - id: TEMPERATURE_LOG_1.0.to_string(), - store_id: Some("store_a".to_string()), - location_id: None, - temperature: 10.6, - sensor_id: "cf5812e0c33911eb9757779d39ae2dbd".to_string(), - timestamp: NaiveDate::from_ymd_opt(2023, 7, 1) - .unwrap() - .and_hms_opt(0, 0, 0) - .unwrap() - + Duration::seconds(47046), - }), - )] -} - -pub(crate) fn test_push_records() -> Vec { - vec![TestSyncPushRecord { - table_name: LegacyTableName::TEMPERATURE_LOG.to_string(), - record_id: TEMPERATURE_LOG_1.0.to_string(), - push_data: json!(LegacyTemperatureLogRow { - id: TEMPERATURE_LOG_1.0.to_string(), - temperature: 10.6, - sensor_id: "cf5812e0c33911eb9757779d39ae2dbd".to_string(), - store_id: Some("store_a".to_string()), - location_id: None, - date: NaiveDate::from_ymd_opt(2023, 7, 1).unwrap(), - time: NaiveTime::from_hms_opt(13, 4, 6).unwrap(), - }), - }] -} +use crate::sync::translations::{ + temperature_log::LegacyTemperatureLogRow, LegacyTableName, PullUpsertRecord, +}; + +use chrono::{Duration, NaiveDate, NaiveTime}; +use repository::TemperatureLogRow; +use serde_json::json; + +use super::{TestSyncPullRecord, TestSyncPushRecord}; + +const TEMPERATURE_LOG_1: (&'static str, &'static str) = ( + "995812e0c33911eb9757779d39ae2dbd", + r#"{ + "ID": "995812e0c33911eb9757779d39ae2dbd", + "sensor_ID": "cf5812e0c33911eb9757779d39ae2dbd", + "location_ID": "", + "temperature": 10.6, + "store_ID": "store_a", + "date": "2023-07-01", + "time": 47046 + }"#, +); + +pub(crate) fn test_pull_upsert_records() -> Vec { + vec![TestSyncPullRecord::new_pull_upsert( + LegacyTableName::TEMPERATURE_LOG, + TEMPERATURE_LOG_1, + PullUpsertRecord::TemperatureLog(TemperatureLogRow { + id: TEMPERATURE_LOG_1.0.to_string(), + store_id: Some("store_a".to_string()), + location_id: None, + temperature: 10.6, + sensor_id: "cf5812e0c33911eb9757779d39ae2dbd".to_string(), + timestamp: NaiveDate::from_ymd_opt(2023, 7, 1) + .unwrap() + .and_hms_opt(0, 0, 0) + .unwrap() + + Duration::seconds(47046), + }), + )] +} + +pub(crate) fn test_push_records() -> Vec { + vec![TestSyncPushRecord { + table_name: LegacyTableName::TEMPERATURE_LOG.to_string(), + record_id: TEMPERATURE_LOG_1.0.to_string(), + push_data: json!(LegacyTemperatureLogRow { + id: TEMPERATURE_LOG_1.0.to_string(), + temperature: 10.6, + sensor_id: "cf5812e0c33911eb9757779d39ae2dbd".to_string(), + store_id: Some("store_a".to_string()), + location_id: None, + date: NaiveDate::from_ymd_opt(2023, 7, 1).unwrap(), + time: NaiveTime::from_hms_opt(13, 4, 6).unwrap(), + }), + }] +} diff --git a/server/service/src/sync/translations/mod.rs b/server/service/src/sync/translations/mod.rs index e9342531c6..a453da43fa 100644 --- a/server/service/src/sync/translations/mod.rs +++ b/server/service/src/sync/translations/mod.rs @@ -80,6 +80,7 @@ pub(crate) fn all_translators() -> SyncTranslators { Box::new(sensor::SensorTranslation {}), Box::new(temperature_log::TemperatureLogTranslation {}), Box::new(temperature_breach::TemperatureBreachTranslation {}), + Box::new(temperature_breach_config::TemperatureBreachConfigTranslation {}), Box::new(clinician::ClinicianTranslation {}), Box::new(clinician_store_join::ClinicianStoreJoinTranslation {}), // Remote-Central (site specific) diff --git a/server/service/src/sync/translations/temperature_breach.rs b/server/service/src/sync/translations/temperature_breach.rs index f4a9339a88..1601193565 100644 --- a/server/service/src/sync/translations/temperature_breach.rs +++ b/server/service/src/sync/translations/temperature_breach.rs @@ -24,14 +24,11 @@ fn match_push_table(changelog: &ChangelogRow) -> bool { } #[derive(Deserialize, Serialize, Debug)] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum LegacyTemperatureBreachType { - #[serde(rename = "COLD_CONSECUTIVE")] ColdConsecutive, - #[serde(rename = "HOT_CONSECUTIVE")] HotConsecutive, - #[serde(rename = "COLD_CUMULATIVE")] ColdCumulative, - #[serde(rename = "HOT_CUMULATIVE")] HotCumulative, } diff --git a/server/service/src/sync/translations/temperature_breach_config.rs b/server/service/src/sync/translations/temperature_breach_config.rs index 0f1830782c..d9cf74fe9f 100644 --- a/server/service/src/sync/translations/temperature_breach_config.rs +++ b/server/service/src/sync/translations/temperature_breach_config.rs @@ -43,7 +43,7 @@ pub(crate) struct TemperatureBreachConfigTranslation {} impl SyncTranslation for TemperatureBreachConfigTranslation { fn pull_dependencies(&self) -> PullDependency { PullDependency { - table: LegacyTableName::TEMPERATURE_BREACH, + table: LegacyTableName::TEMPERATURE_BREACH_CONFIG, dependencies: vec![LegacyTableName::STORE], } }