fix(cli): stream without transaction
All checks were successful
/ build (push) Successful in 10m10s

This commit is contained in:
əlemi 2025-02-12 13:06:51 +01:00
parent cc9f3c85da
commit e6d6de4cc6
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -5,28 +5,26 @@ pub async fn fix_attachments_types(ctx: upub::Context) -> Result<(), Box<dyn std
tracing::info!("fixing attachments documentType...");
let tx = ctx.db().begin().await?;
{
let mut stream = upub::model::attachment::Entity::find()
.filter(upub::model::attachment::Column::DocumentType.eq(apb::DocumentType::Document))
.stream(&tx)
.await?;
let mut stream = upub::model::attachment::Entity::find()
.filter(upub::model::attachment::Column::DocumentType.eq(apb::DocumentType::Document))
.stream(ctx.db())
.await?;
while let Some(attachment) = stream.try_next().await? {
let Some((mime_kind, _mime_type)) = attachment.media_type.split_once('/') else { continue };
while let Some(attachment) = stream.try_next().await? {
let Some((mime_kind, _mime_type)) = attachment.media_type.split_once('/') else { continue };
let document_type = match mime_kind {
"image" => apb::DocumentType::Image,
"video" => apb::DocumentType::Video,
"audio" => apb::DocumentType::Audio,
"text" => apb::DocumentType::Page,
_ => continue,
};
let document_type = match mime_kind {
"image" => apb::DocumentType::Image,
"video" => apb::DocumentType::Video,
"audio" => apb::DocumentType::Audio,
"text" => apb::DocumentType::Page,
_ => continue,
};
tracing::info!("updating {} to {document_type}", attachment.url);
let mut active = attachment.into_active_model();
active.document_type = Set(document_type);
active.update(&tx).await?;
}
tracing::info!("updating {} to {document_type}", attachment.url);
let mut active = attachment.into_active_model();
active.document_type = Set(document_type);
active.update(&tx).await?;
}
tracing::info!("committing transaction...");