Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 42 additions & 2 deletions src/utils/consistency/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(super) async fn load(conn: &mut sqlx::PgConnection, config: &Config) -> Resu
releases.id IS NULL
)
) AS inp
ORDER BY name, version"#,
ORDER BY name"#,
config.build_attempts as i32,
)
.fetch_all(conn)
Expand All @@ -43,13 +43,15 @@ pub(super) async fn load(conn: &mut sqlx::PgConnection, config: &Config) -> Resu
let mut crates = Crates::new();

for (crate_name, release_rows) in &rows.iter().chunk_by(|row| row.name.clone()) {
let releases: Releases = release_rows
let mut releases: Releases = release_rows
.map(|row| Release {
version: row.version.clone(),
yanked: row.yanked,
})
.collect();

releases.sort_by(|lhs, rhs| lhs.version.cmp(&rhs.version));

crates.push(Crate {
name: crate_name,
releases,
Expand All @@ -63,6 +65,7 @@ pub(super) async fn load(conn: &mut sqlx::PgConnection, config: &Config) -> Resu
mod tests {
use super::*;
use crate::test::{V1, V2, V3, async_wrapper};
use pretty_assertions::assert_eq;

#[test]
fn test_load() {
Expand All @@ -84,6 +87,35 @@ mod tests {
.create()
.await?;

// these two releases are there to ensure we sort correctly.
// In the past, we sorted the version (from the crates index & our database)
// as string, which lead to "0.10.3" coming before "0.9.3".
// When both sides are sorted the same way, this is fine and doesn't break the
// consistency check.
// But after migrating everything to using `semver::Version`, the sorting changed
// on the index-side, while we still sorted by string on the database side.
//
// Since I still run the consistency check manually, every now and then, this wasn't
// an issue, because I saw the odd huge difference.
//
// The solution is to sort both sides semver correctly.
const V0_9_3: Version = Version::new(0, 9, 3);
const V0_10_3: Version = Version::new(0, 10, 3);
env.fake_release()
.await
.name("krate")
.version(V0_9_3)
.yanked(false)
.create()
.await?;
env.fake_release()
.await
.name("krate")
.version(V0_10_3)
.yanked(false)
.create()
.await?;

let mut conn = env.async_db().async_conn().await;
let result = load(&mut conn, env.config()).await?;

Expand All @@ -93,6 +125,14 @@ mod tests {
Crate {
name: "krate".into(),
releases: vec![
Release {
version: V0_9_3,
yanked: Some(false),
},
Release {
version: V0_10_3,
yanked: Some(false),
},
Release {
version: V2,
yanked: Some(false),
Expand Down
Loading