Skip to content

Commit c4d8d5d

Browse files
committed
make fields not nullable
fixes crash when accessing built local documentation
1 parent 70df1de commit c4d8d5d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/db/add_package.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ fn read_rust_doc(file_path: &Path) -> Result<Option<String>> {
288288
/// Get release_time, yanked and downloads from crates.io
289289
fn get_release_time_yanked_downloads(
290290
pkg: &MetadataPackage,
291-
) -> Result<(Option<time::Timespec>, Option<bool>, Option<i32>)> {
291+
) -> Result<(time::Timespec, bool, i32)> {
292292
let url = format!("https://crates.io/api/v1/crates/{}/versions", pkg.name);
293293
// FIXME: There is probably better way to do this
294294
// and so many unwraps...
@@ -332,7 +332,7 @@ fn get_release_time_yanked_downloads(
332332
}
333333
}
334334

335-
Ok((release_time, yanked, downloads))
335+
Ok((release_time.unwrap_or(time::get_time()), yanked.unwrap_or(false), downloads.unwrap_or(0)))
336336
}
337337

338338

src/db/migrate.rs

+10
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ pub fn migrate(version: Option<Version>) -> CratesfyiResult<()> {
193193
// downgrade query
194194
"DROP TABLE sandbox_overrides;"
195195
),
196+
migration!(
197+
4,
198+
"Make more fields not null",
199+
"ALTER TABLE releases ALTER COLUMN release_time SET NOT NULL,
200+
ALTER COLUMN yanked SET NOT NULL,
201+
ALTER COLUMN downloads SET NOT NULL",
202+
"ALTER TABLE releases ALTER COLUMN release_time DROP NOT NULL,
203+
ALTER COLUMN yanked DROP NOT NULL,
204+
ALTER COLUMN downloads DROP NOT NULL"
205+
)
196206
];
197207

198208
for migration in migrations {

0 commit comments

Comments
 (0)