From 60e926fc9d6f11c4a58a4a4aa69786fe5dca131c Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 24 Oct 2024 15:47:04 +0200 Subject: [PATCH] database: Change `versions.crate_size` to be `NOT NULL` --- crates/crates_io_database/src/schema.rs | 4 ++-- .../2024-11-14-094209_make-crate-size-not-null/down.sql | 2 ++ migrations/2024-11-14-094209_make-crate-size-not-null/up.sql | 2 ++ src/models/default_versions.rs | 1 + src/models/version.rs | 2 +- src/tests/routes/crates/read.rs | 4 ++-- src/tests/worker/rss/sync_crate_feed.rs | 1 + src/tests/worker/rss/sync_updates_feed.rs | 1 + src/views.rs | 4 ++-- src/worker/jobs/archive_version_downloads.rs | 1 + src/worker/jobs/downloads/process_log.rs | 1 + src/worker/jobs/rss/sync_crate_feed.rs | 1 + src/worker/jobs/rss/sync_updates_feed.rs | 1 + 13 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 migrations/2024-11-14-094209_make-crate-size-not-null/down.sql create mode 100644 migrations/2024-11-14-094209_make-crate-size-not-null/up.sql diff --git a/crates/crates_io_database/src/schema.rs b/crates/crates_io_database/src/schema.rs index 4867624d98d..1fe23e88ace 100644 --- a/crates/crates_io_database/src/schema.rs +++ b/crates/crates_io_database/src/schema.rs @@ -954,10 +954,10 @@ diesel::table! { license -> Nullable, /// The `crate_size` column of the `versions` table. /// - /// Its SQL type is `Nullable`. + /// Its SQL type is `Int4`. /// /// (Automatically generated by Diesel.) - crate_size -> Nullable, + crate_size -> Int4, /// The `published_by` column of the `versions` table. /// /// Its SQL type is `Nullable`. diff --git a/migrations/2024-11-14-094209_make-crate-size-not-null/down.sql b/migrations/2024-11-14-094209_make-crate-size-not-null/down.sql new file mode 100644 index 00000000000..70d26b931b4 --- /dev/null +++ b/migrations/2024-11-14-094209_make-crate-size-not-null/down.sql @@ -0,0 +1,2 @@ +alter table versions + alter column crate_size drop not null; diff --git a/migrations/2024-11-14-094209_make-crate-size-not-null/up.sql b/migrations/2024-11-14-094209_make-crate-size-not-null/up.sql new file mode 100644 index 00000000000..9c79aa7a836 --- /dev/null +++ b/migrations/2024-11-14-094209_make-crate-size-not-null/up.sql @@ -0,0 +1,2 @@ +alter table versions + alter column crate_size set not null; diff --git a/src/models/default_versions.rs b/src/models/default_versions.rs index 96d7c8b454a..6698ceffb0b 100644 --- a/src/models/default_versions.rs +++ b/src/models/default_versions.rs @@ -256,6 +256,7 @@ mod tests { versions::num.eq(num), versions::num_no_build.eq(num), versions::checksum.eq(""), + versions::crate_size.eq(0), )) .execute(conn) .unwrap(); diff --git a/src/models/version.rs b/src/models/version.rs index b8498380d18..a5be0c06a6e 100644 --- a/src/models/version.rs +++ b/src/models/version.rs @@ -24,7 +24,7 @@ pub struct Version { pub features: serde_json::Value, pub yanked: bool, pub license: Option, - pub crate_size: Option, + pub crate_size: i32, pub published_by: Option, pub checksum: String, pub links: Option, diff --git a/src/tests/routes/crates/read.rs b/src/tests/routes/crates/read.rs index 497df856633..04d885d4e19 100644 --- a/src/tests/routes/crates/read.rs +++ b/src/tests/routes/crates/read.rs @@ -131,7 +131,7 @@ async fn version_size() { .iter() .find(|v| v.num == "1.0.0") .expect("Could not find v1.0.0"); - assert_eq!(version1.crate_size, Some(158)); + assert_eq!(version1.crate_size, 158); let version2 = crate_json .versions @@ -140,7 +140,7 @@ async fn version_size() { .iter() .find(|v| v.num == "2.0.0") .expect("Could not find v2.0.0"); - assert_eq!(version2.crate_size, Some(184)); + assert_eq!(version2.crate_size, 184); } #[tokio::test(flavor = "multi_thread")] diff --git a/src/tests/worker/rss/sync_crate_feed.rs b/src/tests/worker/rss/sync_crate_feed.rs index 92a9968d828..1945d66b4f9 100644 --- a/src/tests/worker/rss/sync_crate_feed.rs +++ b/src/tests/worker/rss/sync_crate_feed.rs @@ -73,6 +73,7 @@ async fn create_version( versions::created_at.eq(publish_time), versions::updated_at.eq(publish_time), versions::checksum.eq("checksum"), + versions::crate_size.eq(0), )) .returning(versions::id) .get_result(conn) diff --git a/src/tests/worker/rss/sync_updates_feed.rs b/src/tests/worker/rss/sync_updates_feed.rs index d1177eaa9d2..c653d33b7cb 100644 --- a/src/tests/worker/rss/sync_updates_feed.rs +++ b/src/tests/worker/rss/sync_updates_feed.rs @@ -79,6 +79,7 @@ async fn create_version( versions::created_at.eq(publish_time), versions::updated_at.eq(publish_time), versions::checksum.eq("checksum"), + versions::crate_size.eq(0), )) .returning(versions::id) .get_result(conn) diff --git a/src/views.rs b/src/views.rs index dfc90c72eab..7ee6e1c7a7c 100644 --- a/src/views.rs +++ b/src/views.rs @@ -579,7 +579,7 @@ pub struct EncodableVersion { // NOTE: Used by shields.io, altering `license` requires a PR with shields.io pub license: Option, pub links: EncodableVersionLinks, - pub crate_size: Option, + pub crate_size: i32, pub published_by: Option, pub audit_actions: Vec, pub checksum: String, @@ -763,7 +763,7 @@ mod tests { version_downloads: "".to_string(), authors: "".to_string(), }, - crate_size: Some(1234), + crate_size: 1234, checksum: String::new(), rust_version: None, has_lib: None, diff --git a/src/worker/jobs/archive_version_downloads.rs b/src/worker/jobs/archive_version_downloads.rs index 7454bf4c66b..8669ad92732 100644 --- a/src/worker/jobs/archive_version_downloads.rs +++ b/src/worker/jobs/archive_version_downloads.rs @@ -399,6 +399,7 @@ mod tests { versions::num.eq(num), versions::num_no_build.eq(num), versions::checksum.eq(""), + versions::crate_size.eq(0), )) .returning(versions::id) .get_result(conn) diff --git a/src/worker/jobs/downloads/process_log.rs b/src/worker/jobs/downloads/process_log.rs index 48e446adf94..769085695b9 100644 --- a/src/worker/jobs/downloads/process_log.rs +++ b/src/worker/jobs/downloads/process_log.rs @@ -521,6 +521,7 @@ mod tests { versions::num.eq(version), versions::num_no_build.eq(version), versions::checksum.eq("checksum"), + versions::crate_size.eq(0), )) .execute(conn) .await diff --git a/src/worker/jobs/rss/sync_crate_feed.rs b/src/worker/jobs/rss/sync_crate_feed.rs index 9ff33fac7a9..50e67f136e6 100644 --- a/src/worker/jobs/rss/sync_crate_feed.rs +++ b/src/worker/jobs/rss/sync_crate_feed.rs @@ -263,6 +263,7 @@ mod tests { versions::created_at.eq(publish_time), versions::updated_at.eq(publish_time), versions::checksum.eq("checksum"), + versions::crate_size.eq(0), )) .returning(versions::id) .get_result(conn); diff --git a/src/worker/jobs/rss/sync_updates_feed.rs b/src/worker/jobs/rss/sync_updates_feed.rs index ae2829eb709..fbf63f2b5b2 100644 --- a/src/worker/jobs/rss/sync_updates_feed.rs +++ b/src/worker/jobs/rss/sync_updates_feed.rs @@ -257,6 +257,7 @@ mod tests { versions::created_at.eq(publish_time), versions::updated_at.eq(publish_time), versions::checksum.eq("checksum"), + versions::crate_size.eq(0), )) .returning(versions::id) .get_result(conn);