feat: add endpoint to aid with db migration
ci/woodpecker/push/woodpecker Pipeline was successful Details

feat/type-attributes
Tomáš Mládek 2023-07-03 17:18:55 +02:00
parent 244abd64aa
commit 2b4c1e7976
3 changed files with 33 additions and 1 deletions

View File

@ -855,6 +855,17 @@ pub async fn get_info(state: web::Data<State>) -> Result<HttpResponse, Error> {
})))
}
#[get("/api/migration/user-entries")]
pub async fn get_user_entries(state: web::Data<State>) -> Result<HttpResponse, Error> {
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
let result = web::block(move || connection.get_explicit_entries())
.await?
.map_err(ErrorInternalServerError)?;
Ok(HttpResponse::Ok().json(result.as_hash().map_err(ErrorInternalServerError)?))
}
#[derive(Debug)]
enum ExternalFetchError {
Status(anyhow::Error),

View File

@ -63,7 +63,8 @@ where
.service(routes::vault_stats)
.service(routes::store_stats)
.service(routes::get_jobs)
.service(routes::get_info);
.service(routes::get_info)
.service(routes::get_user_entries);
if let Some(ui_path) = ui_path {
return app

View File

@ -409,6 +409,26 @@ impl UpEndConnection {
}
}))
}
#[deprecated]
pub fn get_explicit_entries(&self) -> Result<Vec<Entry>> {
use crate::database::inner::schema::data::dsl::*;
let _lock = self.lock.read().unwrap();
let conn = self.pool.get()?;
let result: Vec<models::Entry> = data
.filter(
provenance
.like("API%")
.and(provenance.not_like("%IMPLICIT%")),
)
.load(&conn)?;
Ok(result
.iter()
.map(Entry::try_from)
.collect::<Result<Vec<Entry>>>()?)
}
}
#[cfg(test)]