diff --git a/.sqlx/query-77054c7c20195a2a7766eb83bf39add56ec84bb502ce39d26cd9394703bdd71a.json b/.sqlx/query-1ad61bdc8babbb4403c535318ccf657b3ea98a04126539ccf08f8251d87ed32b.json similarity index 78% rename from .sqlx/query-77054c7c20195a2a7766eb83bf39add56ec84bb502ce39d26cd9394703bdd71a.json rename to .sqlx/query-1ad61bdc8babbb4403c535318ccf657b3ea98a04126539ccf08f8251d87ed32b.json index 681ebd0e..918cd5b7 100644 --- a/.sqlx/query-77054c7c20195a2a7766eb83bf39add56ec84bb502ce39d26cd9394703bdd71a.json +++ b/.sqlx/query-1ad61bdc8babbb4403c535318ccf657b3ea98a04126539ccf08f8251d87ed32b.json @@ -1,6 +1,6 @@ { "db_name": "SQLite", - "query": "INSERT INTO beamline\n (name, scan_number, visit, scan, detector, fallback_extension)\n VALUES\n (?,?,?,?,?,?)\n RETURNING *", + "query": "INSERT INTO beamline\n (name, scan_number, visit, scan, detector, tracker_file_extension)\n VALUES\n (?,?,?,?,?,?)\n RETURNING *", "describe": { "columns": [ { @@ -34,7 +34,7 @@ "type_info": "Text" }, { - "name": "fallback_extension", + "name": "tracker_file_extension", "ordinal": 6, "type_info": "Text" } @@ -52,5 +52,5 @@ true ] }, - "hash": "77054c7c20195a2a7766eb83bf39add56ec84bb502ce39d26cd9394703bdd71a" + "hash": "1ad61bdc8babbb4403c535318ccf657b3ea98a04126539ccf08f8251d87ed32b" } diff --git a/.sqlx/query-7b769dea685f49e8ff6d24a69e69e7037c1dc197db8bd273ec53e63a85e85351.json b/.sqlx/query-7b769dea685f49e8ff6d24a69e69e7037c1dc197db8bd273ec53e63a85e85351.json index 7c487d0f..d115f042 100644 --- a/.sqlx/query-7b769dea685f49e8ff6d24a69e69e7037c1dc197db8bd273ec53e63a85e85351.json +++ b/.sqlx/query-7b769dea685f49e8ff6d24a69e69e7037c1dc197db8bd273ec53e63a85e85351.json @@ -34,7 +34,7 @@ "type_info": "Text" }, { - "name": "fallback_extension", + "name": "tracker_file_extension", "ordinal": 6, "type_info": "Text" } diff --git a/.sqlx/query-e45d346b58374c69e4f3bb59935719177993012eb03ce8f2d9bcca00290690be.json b/.sqlx/query-e45d346b58374c69e4f3bb59935719177993012eb03ce8f2d9bcca00290690be.json index 565f1f3a..ea9c2442 100644 --- a/.sqlx/query-e45d346b58374c69e4f3bb59935719177993012eb03ce8f2d9bcca00290690be.json +++ b/.sqlx/query-e45d346b58374c69e4f3bb59935719177993012eb03ce8f2d9bcca00290690be.json @@ -34,7 +34,7 @@ "type_info": "Text" }, { - "name": "fallback_extension", + "name": "tracker_file_extension", "ordinal": 6, "type_info": "Text" } diff --git a/migrations/0002_extension_name.down.sql b/migrations/0002_extension_name.down.sql new file mode 100644 index 00000000..1afd31fd --- /dev/null +++ b/migrations/0002_extension_name.down.sql @@ -0,0 +1,3 @@ +-- Revert back to fallback_extension name +ALTER TABLE beamline +RENAME COLUMN tracker_file_extension TO fallback_extension; diff --git a/migrations/0002_extension_name.up.sql b/migrations/0002_extension_name.up.sql new file mode 100644 index 00000000..70d47de6 --- /dev/null +++ b/migrations/0002_extension_name.up.sql @@ -0,0 +1,3 @@ +-- Rename column to match renamed struct field +ALTER TABLE beamline +RENAME COLUMN fallback_extension TO tracker_file_extension; diff --git a/src/db_service.rs b/src/db_service.rs index c0e7a362..00fbfbca 100644 --- a/src/db_service.rs +++ b/src/db_service.rs @@ -66,7 +66,7 @@ pub struct BeamlineConfiguration { visit: RawPathTemplate, scan: RawPathTemplate, detector: RawPathTemplate, - extension: Option, + tracker_file_extension: Option, } impl BeamlineConfiguration { @@ -78,8 +78,8 @@ impl BeamlineConfiguration { self.scan_number } - pub fn extension(&self) -> Option<&str> { - self.extension.as_deref() + pub fn tracker_file_extension(&self) -> Option<&str> { + self.tracker_file_extension.as_deref() } pub fn visit(&self) -> SqliteTemplateResult { @@ -104,7 +104,7 @@ impl<'r> FromRow<'r, SqliteRow> for BeamlineConfiguration { visit: row.try_get::("visit")?, scan: row.try_get::("scan")?, detector: row.try_get::("detector")?, - fallback_extension: row.try_get::, _>("fallback_extension")?, + tracker_file_extension: row.try_get::, _>("tracker_file_extension")?, } .into()) } @@ -117,7 +117,7 @@ pub struct BeamlineConfigurationUpdate { pub visit: Option>, pub scan: Option>, pub detector: Option>, - pub extension: Option, + pub tracker_file_extension: Option, } impl BeamlineConfigurationUpdate { @@ -126,7 +126,7 @@ impl BeamlineConfigurationUpdate { && self.visit.is_none() && self.scan.is_none() && self.detector.is_none() - && self.extension.is_none() + && self.tracker_file_extension.is_none() } pub async fn update_beamline( @@ -158,10 +158,10 @@ impl BeamlineConfigurationUpdate { fields.push("detector="); fields.push_bind_unseparated(detector.to_string()); } - if let Some(ext) = &self.extension { + if let Some(ext) = &self.tracker_file_extension { if ext != &self.name { // extension defaults to beamline name - fields.push("fallback_extension="); + fields.push("tracker_file_extension="); fields.push_bind_unseparated(ext); } } @@ -188,7 +188,7 @@ impl BeamlineConfigurationUpdate { visit: self.visit.ok_or("visit")?.to_string(), scan: self.scan.ok_or("scan")?.to_string(), detector: self.detector.ok_or("detector")?.to_string(), - fallback_extension: self.extension, + tracker_file_extension: self.tracker_file_extension, }; Ok(dbc.insert_into(db).await?) } @@ -200,7 +200,7 @@ impl BeamlineConfigurationUpdate { visit: None, scan: None, detector: None, - extension: None, + tracker_file_extension: None, } } } @@ -214,7 +214,7 @@ struct DbBeamlineConfig { visit: String, scan: String, detector: String, - fallback_extension: Option, + tracker_file_extension: Option, } impl DbBeamlineConfig { @@ -225,7 +225,7 @@ impl DbBeamlineConfig { let bc = query_as!( DbBeamlineConfig, "INSERT INTO beamline - (name, scan_number, visit, scan, detector, fallback_extension) + (name, scan_number, visit, scan, detector, tracker_file_extension) VALUES (?,?,?,?,?,?) RETURNING *", @@ -234,7 +234,7 @@ impl DbBeamlineConfig { self.visit, self.scan, self.detector, - self.fallback_extension + self.tracker_file_extension ) .fetch_one(&db.pool) .await?; @@ -250,7 +250,7 @@ impl From for BeamlineConfiguration { visit: value.visit.into(), scan: value.scan.into(), detector: value.detector.into(), - extension: value.fallback_extension, + tracker_file_extension: value.tracker_file_extension, } } } @@ -440,7 +440,7 @@ mod db_tests { "{subdirectory}/{instrument}-{scan_number}-{detector}", ) .ok(), - extension: Some("ext".into()), + tracker_file_extension: Some("ext".into()), } } @@ -471,7 +471,7 @@ mod db_tests { } #[rstest] - #[case::directory(|u: &mut BeamlineConfigurationUpdate| u.extension = None)] + #[case::directory(|u: &mut BeamlineConfigurationUpdate| u.tracker_file_extension = None)] #[case::scan_number(|u: &mut BeamlineConfigurationUpdate| u.scan_number = None)] #[tokio::test] async fn new_beamline_without_optional( @@ -565,7 +565,7 @@ mod db_tests { conf.detector().unwrap().to_string(), "{subdirectory}/{instrument}-{scan_number}-{detector}" ); - let Some(ext) = conf.extension() else { + let Some(ext) = conf.tracker_file_extension() else { panic!("Missing extension"); }; assert_eq!(ext, "ext"); @@ -587,8 +587,8 @@ mod db_tests { |u: &mut Update| u.scan_number = Some(42), |u: BeamlineConfiguration| assert_eq!(u.scan_number(), 42))] #[case::extension( - |u: &mut Update| u.extension = Some("new".into()), - |u: BeamlineConfiguration| assert_eq!(u.extension().unwrap(), "new"))] + |u: &mut Update| u.tracker_file_extension = Some("new".into()), + |u: BeamlineConfiguration| assert_eq!(u.tracker_file_extension().unwrap(), "new"))] #[tokio::test] async fn update_existing( #[future(awt)] db: SqliteScanPathService, diff --git a/src/graphql.rs b/src/graphql.rs index 4b1f7bae..cf3945f5 100644 --- a/src/graphql.rs +++ b/src/graphql.rs @@ -325,14 +325,16 @@ impl Mutation { // while the DB is being queried or between the two queries but there // isn't much we can do from here. let current = db.current_configuration(&beamline).await?; - let dir = nt.for_beamline(&beamline, current.extension()).await?; + let dir = nt + .for_beamline(&beamline, current.tracker_file_extension()) + .await?; let next_scan = db .next_scan_configuration(&beamline, dir.prev().await?) .await?; if let Err(e) = dir.set(next_scan.scan_number()).await { - warn!("Failed to increment fallback tracker directory: {e}"); + warn!("Failed to increment tracker file: {e}"); } Ok(ScanPaths { @@ -386,7 +388,7 @@ struct ConfigurationUpdates { scan: Option>, detector: Option>, scan_number: Option, - extension: Option, + tracker_file_extension: Option, } impl ConfigurationUpdates { @@ -397,7 +399,7 @@ impl ConfigurationUpdates { visit: self.visit.map(|t| t.0), scan: self.scan.map(|t| t.0), detector: self.detector.map(|t| t.0), - extension: self.extension, + tracker_file_extension: self.tracker_file_extension, } } } @@ -597,7 +599,7 @@ mod tests { scan: scan.map(|s| InputTemplate::parse(Some(Value::String(s.into()))).unwrap()), detector: det.map(|d| InputTemplate::parse(Some(Value::String(d.into()))).unwrap()), scan_number: num, - extension: ext.map(|e| e.into()), + tracker_file_extension: ext.map(|e| e.into()), } } diff --git a/static/service_schema b/static/service_schema index 2bd269f4..45b9c1a0 100644 --- a/static/service_schema +++ b/static/service_schema @@ -11,7 +11,7 @@ input ConfigurationUpdates { scan: ScanTemplate detector: DetectorTemplate scanNumber: Int - extension: String + trackerFileExtension: String } scalar Detector