Force files to be unique, require all new versions to have at least one file (#236)

This commit is contained in:
Geometrically
2021-08-21 19:38:32 -07:00
committed by GitHub
parent ffd9a34cf5
commit 4073a7abc3
4 changed files with 98 additions and 4 deletions

View File

@@ -240,6 +240,26 @@ pub async fn delete_file(
}
}
use futures::stream::TryStreamExt;
let files = sqlx::query!(
"
SELECT f.id id FROM files f
WHERE f.version_id = $1
",
row.version_id
)
.fetch_many(&**pool)
.try_filter_map(|e| async { Ok(e.right().map(|_| ())) })
.try_collect::<Vec<()>>()
.await?;
if files.len() < 2 {
return Err(ApiError::InvalidInputError(
"Versions must have at least one file uploaded to them".to_string(),
));
}
let mut transaction = pool.begin().await?;
sqlx::query!(