Skip to content

database: Change num_no_build to be NOT NULL #9767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2024
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
2 changes: 1 addition & 1 deletion crates/crates_io_database/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ diesel::table! {
/// message associated with a yanked version
yank_message -> Nullable<Text>,
/// This is the same as `num` without the optional "build metadata" part (except for some versions that were published before we started validating this).
num_no_build -> Nullable<Varchar>,
num_no_build -> Varchar,
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table versions
alter column num_no_build drop not null;
2 changes: 2 additions & 0 deletions migrations/2024-10-24-134209_make-unique-num-not-null/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table versions
alter column num_no_build set not null;
1 change: 1 addition & 0 deletions src/models/default_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ mod tests {
.values((
versions::crate_id.eq(crate_id),
versions::num.eq(num),
versions::num_no_build.eq(num),
versions::checksum.eq(""),
))
.execute(conn)
Expand Down
4 changes: 3 additions & 1 deletion src/models/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct Version {
pub has_lib: Option<bool>,
pub bin_names: Option<Vec<Option<String>>>,
pub yank_message: Option<String>,
pub num_no_build: Option<String>,
pub num_no_build: String,
}

impl Version {
Expand Down Expand Up @@ -85,6 +85,8 @@ pub struct NewVersion<'a> {
crate_id: i32,
#[builder(start_fn)]
num: &'a str,
#[builder(default = strip_build_metadata(num))]
num_no_build: &'a str,
Comment on lines +88 to +89
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argh, I screwed this up... this part of the diff should've been in the previous PR instead. every new version is currently inserted with num_no_build = NULL, which makes the set not null migration in this PR fail 🤦‍♂️

update versions
set num_no_build = split_part(num, '+', 1)
where num_no_build IS NULL;

I will run ⬆️ right before deploying, which should be enough for this to deploy cleanly...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright, that worked. all good now! :)

created_at: Option<&'a NaiveDateTime>,
yanked: Option<bool>,
#[builder(default = serde_json::Value::Object(Default::default()))]
Expand Down
1 change: 1 addition & 0 deletions src/tests/worker/rss/sync_crate_feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async fn create_version(
.values((
versions::crate_id.eq(crate_id),
versions::num.eq(version),
versions::num_no_build.eq(version),
versions::created_at.eq(publish_time),
versions::updated_at.eq(publish_time),
versions::checksum.eq("checksum"),
Expand Down
1 change: 1 addition & 0 deletions src/tests/worker/rss/sync_updates_feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ async fn create_version(
.values((
versions::crate_id.eq(crate_id),
versions::num.eq(version),
versions::num_no_build.eq(version),
versions::created_at.eq(publish_time),
versions::updated_at.eq(publish_time),
versions::checksum.eq("checksum"),
Expand Down
1 change: 1 addition & 0 deletions src/worker/jobs/archive_version_downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ mod tests {
.values((
versions::crate_id.eq(crate_id),
versions::num.eq(num),
versions::num_no_build.eq(num),
versions::checksum.eq(""),
))
.returning(versions::id)
Expand Down
1 change: 1 addition & 0 deletions src/worker/jobs/downloads/process_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ mod tests {
.values((
versions::crate_id.eq(crate_id),
versions::num.eq(version),
versions::num_no_build.eq(version),
versions::checksum.eq("checksum"),
))
.execute(conn)
Expand Down
4 changes: 3 additions & 1 deletion src/worker/jobs/rss/sync_crate_feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,12 @@ mod tests {
version: impl Into<Cow<'static, str>>,
publish_time: NaiveDateTime,
) -> impl Future<Output = i32> {
let version = version.into();
let future = diesel::insert_into(versions::table)
.values((
versions::crate_id.eq(crate_id),
versions::num.eq(version.into()),
versions::num.eq(version.clone()),
versions::num_no_build.eq(version),
versions::created_at.eq(publish_time),
versions::updated_at.eq(publish_time),
versions::checksum.eq("checksum"),
Expand Down
4 changes: 3 additions & 1 deletion src/worker/jobs/rss/sync_updates_feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,12 @@ mod tests {
version: impl Into<Cow<'static, str>>,
publish_time: NaiveDateTime,
) -> impl Future<Output = i32> {
let version = version.into();
let future = diesel::insert_into(versions::table)
.values((
versions::crate_id.eq(crate_id),
versions::num.eq(version.into()),
versions::num.eq(version.clone()),
versions::num_no_build.eq(version),
versions::created_at.eq(publish_time),
versions::updated_at.eq(publish_time),
versions::checksum.eq("checksum"),
Expand Down