blob: 5ef07d7aea4de4f9ac5505a30fe6d02c3a8713f1 [file]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
use super::*;
use maka_agent_facts::durable::RunId;
pub struct OriginalUserRun(pub RunId);
impl Query for OriginalUserRun {
type Output = Option<bool>;
fn execute(self, c: &Connection) -> Result<Self::Output, StoreError> {
Ok(
c.prepare_cached("SELECT original_user_run FROM agent_run_specs WHERE run=?")?
.query_row([self.0.to_string()], |r| r.get(0))
.optional()?
.flatten(),
)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn migration_0058_unwraps_recap_receipts() {
let db = Connection::open_in_memory().unwrap();
let catalog: Vec<_> = maka_event_log::ROOT_MIGRATIONS
.iter()
.chain(crate::MIGRATIONS)
.copied()
.collect();
let through_55: Vec<_> = catalog
.iter()
.copied()
.filter(|m| m.version <= 55)
.collect();
maka_event_log::migration::run(&db, &through_55).unwrap();
db.execute_batch(
r#"INSERT INTO session_control(id,fingerprint,revision,created_at,updated_at,archived,configuration)
VALUES('source','test',1,0,0,0,'{}');
INSERT INTO plugin_data VALUES('maka.session-recap','profile','old',4,
'{"kind":"ready","operationId":"00000000-0000-0000-0000-000000000000","through":1,"modelId":"m","text":"old"}'),
('maka.session-recap','profile','deleted',5,NULL);"#,
)
.unwrap();
let through_58: Vec<_> = catalog.into_iter().filter(|m| m.version <= 58).collect();
maka_event_log::migration::run(&db, &through_58).unwrap();
let mut rows = db
.prepare("SELECT revision,value_json->>'kind',value_json->>'text' FROM plugin_data ORDER BY revision")
.unwrap();
let receipts = rows
.query_map([], |r| {
Ok((
r.get::<_, i64>(0)?,
r.get::<_, Option<String>>(1)?,
r.get::<_, Option<String>>(2)?,
))
})
.unwrap()
.collect::<Result<Vec<_>, _>>()
.unwrap();
assert_eq!(
receipts,
[
(4, Some("ready".into()), Some("old".into())),
(5, None, None),
]
);
}
}