Skip to content

database/versions: Add new semver_no_prerelease column #4022

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

Closed
wants to merge 2 commits into from
Closed
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
28 changes: 28 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ rustdoc-args = [
[dependencies]
anyhow = "1.0"
base64 = "0.13"
bigdecimal = { version = ">= 0.0.10, < 0.2.0", features = ["serde"] }
cargo-registry-markdown = { path = "cargo-registry-markdown" }
cargo-registry-s3 = { path = "cargo-registry-s3" }
chrono = { version = "0.4.19", features = ["serde"] }
Expand All @@ -49,7 +50,7 @@ cookie = { version = "0.15", features = ["secure"] }
dashmap = { version = "4.0.2", features = ["raw-api"] }
derive_deref = "1.1.1"
dialoguer = "0.9"
diesel = { version = "1.4.8", features = ["postgres", "serde_json", "chrono", "r2d2"] }
diesel = { version = "1.4.8", features = ["postgres", "serde_json", "chrono", "numeric", "r2d2"] }
diesel_full_text_search = "1.0.1"
diesel_migrations = { version = "1.4.0", features = ["postgres"] }
dotenv = "0.15"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE versions
DROP COLUMN semver_no_prerelease;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- add the new column.

ALTER TABLE versions
ADD COLUMN semver_no_prerelease NUMERIC[3];
11 changes: 11 additions & 0 deletions src/models/version.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;

use bigdecimal::BigDecimal;
use chrono::NaiveDateTime;
use diesel::prelude::*;

Expand All @@ -23,6 +24,7 @@ pub struct Version {
pub license: Option<String>,
pub crate_size: Option<i32>,
pub published_by: Option<i32>,
pub semver_no_prerelease: Option<Vec<BigDecimal>>,
}

#[derive(Insertable, Debug)]
Expand All @@ -34,6 +36,7 @@ pub struct NewVersion {
license: Option<String>,
crate_size: Option<i32>,
published_by: i32,
semver_no_prerelease: Option<Vec<BigDecimal>>,
}

/// The highest version (semver order) and the most recently updated version.
Expand Down Expand Up @@ -132,9 +135,17 @@ impl NewVersion {
) -> AppResult<Self> {
let features = serde_json::to_value(features)?;

let semver_no_prerelease = match num {
num if num.pre.is_empty() => {
Some(vec![num.major.into(), num.minor.into(), num.patch.into()])
}
_ => None,
};

let mut new_version = NewVersion {
crate_id,
num: num.to_string(),
semver_no_prerelease,
features,
license,
crate_size: Some(crate_size),
Expand Down
6 changes: 6 additions & 0 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,12 @@ table! {
///
/// (Automatically generated by Diesel.)
published_by -> Nullable<Int4>,
/// The `semver_no_prerelease` column of the `versions` table.
///
/// Its SQL type is `Nullable<Array<Numeric>>`.
///
/// (Automatically generated by Diesel.)
semver_no_prerelease -> Nullable<Array<Numeric>>,
}
}

Expand Down
1 change: 1 addition & 0 deletions src/tasks/dump_db/dump-db.toml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ yanked = "public"
license = "public"
crate_size = "public"
published_by = "public"
semver_no_prerelease = "public"

[versions_published_by.columns]
version_id = "private"
Expand Down