feat: add endpoint to aid with db migration
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
244abd64aa
commit
2b4c1e7976
3 changed files with 33 additions and 1 deletions
|
@ -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),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)]
|
||||
|
|
Loading…
Reference in a new issue