Skip to content

Commit 3f4b4a2

Browse files
authored
database: Change versions.crate_size to be NOT NULL (#9926)
1 parent 6f9226b commit 3f4b4a2

File tree

13 files changed

+18
-7
lines changed

13 files changed

+18
-7
lines changed

crates/crates_io_database/src/schema.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,10 +954,10 @@ diesel::table! {
954954
license -> Nullable<Varchar>,
955955
/// The `crate_size` column of the `versions` table.
956956
///
957-
/// Its SQL type is `Nullable<Int4>`.
957+
/// Its SQL type is `Int4`.
958958
///
959959
/// (Automatically generated by Diesel.)
960-
crate_size -> Nullable<Int4>,
960+
crate_size -> Int4,
961961
/// The `published_by` column of the `versions` table.
962962
///
963963
/// Its SQL type is `Nullable<Int4>`.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
alter table versions
2+
alter column crate_size drop not null;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
alter table versions
2+
alter column crate_size set not null;

src/models/default_versions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ mod tests {
256256
versions::num.eq(num),
257257
versions::num_no_build.eq(num),
258258
versions::checksum.eq(""),
259+
versions::crate_size.eq(0),
259260
))
260261
.execute(conn)
261262
.unwrap();

src/models/version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct Version {
2424
pub features: serde_json::Value,
2525
pub yanked: bool,
2626
pub license: Option<String>,
27-
pub crate_size: Option<i32>,
27+
pub crate_size: i32,
2828
pub published_by: Option<i32>,
2929
pub checksum: String,
3030
pub links: Option<String>,

src/tests/routes/crates/read.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ async fn version_size() {
131131
.iter()
132132
.find(|v| v.num == "1.0.0")
133133
.expect("Could not find v1.0.0");
134-
assert_eq!(version1.crate_size, Some(158));
134+
assert_eq!(version1.crate_size, 158);
135135

136136
let version2 = crate_json
137137
.versions
@@ -140,7 +140,7 @@ async fn version_size() {
140140
.iter()
141141
.find(|v| v.num == "2.0.0")
142142
.expect("Could not find v2.0.0");
143-
assert_eq!(version2.crate_size, Some(184));
143+
assert_eq!(version2.crate_size, 184);
144144
}
145145

146146
#[tokio::test(flavor = "multi_thread")]

src/tests/worker/rss/sync_crate_feed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ async fn create_version(
7373
versions::created_at.eq(publish_time),
7474
versions::updated_at.eq(publish_time),
7575
versions::checksum.eq("checksum"),
76+
versions::crate_size.eq(0),
7677
))
7778
.returning(versions::id)
7879
.get_result(conn)

src/tests/worker/rss/sync_updates_feed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ async fn create_version(
7979
versions::created_at.eq(publish_time),
8080
versions::updated_at.eq(publish_time),
8181
versions::checksum.eq("checksum"),
82+
versions::crate_size.eq(0),
8283
))
8384
.returning(versions::id)
8485
.get_result(conn)

src/views.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ pub struct EncodableVersion {
579579
// NOTE: Used by shields.io, altering `license` requires a PR with shields.io
580580
pub license: Option<String>,
581581
pub links: EncodableVersionLinks,
582-
pub crate_size: Option<i32>,
582+
pub crate_size: i32,
583583
pub published_by: Option<EncodablePublicUser>,
584584
pub audit_actions: Vec<EncodableAuditAction>,
585585
pub checksum: String,
@@ -763,7 +763,7 @@ mod tests {
763763
version_downloads: "".to_string(),
764764
authors: "".to_string(),
765765
},
766-
crate_size: Some(1234),
766+
crate_size: 1234,
767767
checksum: String::new(),
768768
rust_version: None,
769769
has_lib: None,

src/worker/jobs/archive_version_downloads.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ mod tests {
399399
versions::num.eq(num),
400400
versions::num_no_build.eq(num),
401401
versions::checksum.eq(""),
402+
versions::crate_size.eq(0),
402403
))
403404
.returning(versions::id)
404405
.get_result(conn)

0 commit comments

Comments
 (0)