File tree 3 files changed +15
-11
lines changed
crates/crates_io_database/src/models
3 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ pub struct NewVersion<'a> {
91
91
license : Option < & ' a str > ,
92
92
#[ builder( default , name = "size" ) ]
93
93
crate_size : i32 ,
94
- published_by : i32 ,
94
+ published_by : Option < i32 > ,
95
95
checksum : & ' a str ,
96
96
links : Option < & ' a str > ,
97
97
rust_version : Option < & ' a str > ,
@@ -110,7 +110,7 @@ impl NewVersion<'_> {
110
110
pub async fn save (
111
111
& self ,
112
112
conn : & mut AsyncPgConnection ,
113
- published_by_email : & str ,
113
+ published_by_email : Option < & str > ,
114
114
) -> QueryResult < Version > {
115
115
use diesel:: insert_into;
116
116
@@ -122,13 +122,15 @@ impl NewVersion<'_> {
122
122
. get_result ( conn)
123
123
. await ?;
124
124
125
- insert_into ( versions_published_by:: table)
126
- . values ( (
127
- versions_published_by:: version_id. eq ( version. id ) ,
128
- versions_published_by:: email. eq ( published_by_email) ,
129
- ) )
130
- . execute ( conn)
131
- . await ?;
125
+ if let Some ( published_by_email) = published_by_email {
126
+ insert_into ( versions_published_by:: table)
127
+ . values ( (
128
+ versions_published_by:: version_id. eq ( version. id ) ,
129
+ versions_published_by:: email. eq ( published_by_email) ,
130
+ ) )
131
+ . execute ( conn)
132
+ . await ?;
133
+ }
132
134
133
135
Ok ( version)
134
136
}
Original file line number Diff line number Diff line change @@ -110,7 +110,9 @@ impl VersionBuilder {
110
110
. maybe_created_at ( self . created_at . as_ref ( ) )
111
111
. build ( ) ;
112
112
113
- let vers = new_version. save ( connection, "someone@example.com" ) . await ?;
113
+ let vers = new_version
114
+ . save ( connection, Some ( "someone@example.com" ) )
115
+ . await ?;
114
116
115
117
let new_deps = self
116
118
. dependencies
Original file line number Diff line number Diff line change @@ -136,7 +136,7 @@ mod tests {
136
136
. checksum ( "0000000000000000000000000000000000000000000000000000000000000000" )
137
137
. build ( ) ;
138
138
139
- let version = version. save ( conn, "someone@example.com" ) . await . unwrap ( ) ;
139
+ let version = version. save ( conn, None ) . await . unwrap ( ) ;
140
140
( krate, version)
141
141
}
142
142
You can’t perform that action at this time.
0 commit comments