File tree Expand file tree Collapse file tree 5 files changed +24
-0
lines changed
migrations/2021-10-09-074834_versions_add_semver_no_prerelease_column Expand file tree Collapse file tree 5 files changed +24
-0
lines changed Original file line number Diff line number Diff line change
1
+ ALTER TABLE versions
2
+ DROP COLUMN semver_no_prerelease;
Original file line number Diff line number Diff line change
1
+ -- add the new column.
2
+
3
+ ALTER TABLE versions
4
+ ADD COLUMN semver_no_prerelease NUMERIC [3 ];
Original file line number Diff line number Diff line change 1
1
use std:: collections:: HashMap ;
2
2
3
+ use bigdecimal:: BigDecimal ;
3
4
use chrono:: NaiveDateTime ;
4
5
use diesel:: prelude:: * ;
5
6
@@ -23,6 +24,7 @@ pub struct Version {
23
24
pub license : Option < String > ,
24
25
pub crate_size : Option < i32 > ,
25
26
pub published_by : Option < i32 > ,
27
+ pub semver_no_prerelease : Option < Vec < BigDecimal > > ,
26
28
}
27
29
28
30
#[ derive( Insertable , Debug ) ]
@@ -34,6 +36,7 @@ pub struct NewVersion {
34
36
license : Option < String > ,
35
37
crate_size : Option < i32 > ,
36
38
published_by : i32 ,
39
+ semver_no_prerelease : Option < Vec < BigDecimal > > ,
37
40
}
38
41
39
42
/// The highest version (semver order) and the most recently updated version.
@@ -132,9 +135,17 @@ impl NewVersion {
132
135
) -> AppResult < Self > {
133
136
let features = serde_json:: to_value ( features) ?;
134
137
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
+
135
145
let mut new_version = NewVersion {
136
146
crate_id,
137
147
num : num. to_string ( ) ,
148
+ semver_no_prerelease,
138
149
features,
139
150
license,
140
151
crate_size : Some ( crate_size) ,
Original file line number Diff line number Diff line change @@ -982,6 +982,12 @@ table! {
982
982
///
983
983
/// (Automatically generated by Diesel.)
984
984
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 >>,
985
991
}
986
992
}
987
993
Original file line number Diff line number Diff line change @@ -212,6 +212,7 @@ yanked = "public"
212
212
license = " public"
213
213
crate_size = " public"
214
214
published_by = " public"
215
+ semver_no_prerelease = " public"
215
216
216
217
[versions_published_by .columns ]
217
218
version_id = " private"
You can’t perform that action at this time.
0 commit comments