Skip to content

Commit cc66bfa

Browse files
committed
database/versions: Add new semver_no_prerelease column
1 parent 33cce85 commit cc66bfa

File tree

5 files changed

+24
-0
lines changed

5 files changed

+24
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE versions
2+
DROP COLUMN semver_no_prerelease;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- add the new column.
2+
3+
ALTER TABLE versions
4+
ADD COLUMN semver_no_prerelease NUMERIC[3];

src/models/version.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::collections::HashMap;
22

3+
use bigdecimal::BigDecimal;
34
use chrono::NaiveDateTime;
45
use diesel::prelude::*;
56

@@ -23,6 +24,7 @@ pub struct Version {
2324
pub license: Option<String>,
2425
pub crate_size: Option<i32>,
2526
pub published_by: Option<i32>,
27+
pub semver_no_prerelease: Option<Vec<BigDecimal>>,
2628
}
2729

2830
#[derive(Insertable, Debug)]
@@ -34,6 +36,7 @@ pub struct NewVersion {
3436
license: Option<String>,
3537
crate_size: Option<i32>,
3638
published_by: i32,
39+
semver_no_prerelease: Option<Vec<BigDecimal>>,
3740
}
3841

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

138+
let semver_no_prerelease = match num {
139+
num if num.pre.is_empty() => {
140+
Some(vec![num.major.into(), num.minor.into(), num.patch.into()])
141+
}
142+
_ => None,
143+
};
144+
135145
let mut new_version = NewVersion {
136146
crate_id,
137147
num: num.to_string(),
148+
semver_no_prerelease,
138149
features,
139150
license,
140151
crate_size: Some(crate_size),

src/schema.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,12 @@ table! {
982982
///
983983
/// (Automatically generated by Diesel.)
984984
published_by -> Nullable<Int4>,
985+
/// The `semver_no_prerelease` column of the `versions` table.
986+
///
987+
/// Its SQL type is `Nullable<Array<Numeric>>`.
988+
///
989+
/// (Automatically generated by Diesel.)
990+
semver_no_prerelease -> Nullable<Array<Numeric>>,
985991
}
986992
}
987993

src/tasks/dump_db/dump-db.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ yanked = "public"
212212
license = "public"
213213
crate_size = "public"
214214
published_by = "public"
215+
semver_no_prerelease = "public"
215216

216217
[versions_published_by.columns]
217218
version_id = "private"

0 commit comments

Comments
 (0)