Skip to content

Commit 1957a81

Browse files
committed
store date of nightly version in separate field
1 parent 1943e68 commit 1957a81

7 files changed

+139
-9
lines changed

.sqlx/query-b2fa2e823f0f8e8fbd288cd0c102ad28a198463534efbefcf06f45c0f49872af.json .sqlx/query-3340b2af65824ae339c5721cd79896575c0db5049ec4d2f51181dfd4684d274c.json

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-c955871bcda914feac9cfb23fe010399c0b3f75e92ac425fa4ec337e9b250c26.json

+57
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DROP INDEX builds_nightly_date_idx;
2+
3+
ALTER TABLE builds
4+
DROP COLUMN rustc_nightly_date;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ALTER TABLE builds
2+
ADD COLUMN rustc_nightly_date DATE;
3+
4+
CREATE INDEX builds_nightly_date_idx ON builds USING btree (rustc_nightly_date);

src/db/add_package.rs

+69-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
error::Result,
55
registry_api::{CrateData, CrateOwner, ReleaseData},
66
storage::CompressionAlgorithm,
7-
utils::MetadataPackage,
7+
utils::{rustc_version::parse_rustc_date, MetadataPackage},
88
web::crate_details::{latest_release, releases_for_crate},
99
};
1010
use anyhow::Context;
@@ -17,7 +17,7 @@ use std::{
1717
io::{BufRead, BufReader},
1818
path::Path,
1919
};
20-
use tracing::{debug, info, instrument};
20+
use tracing::{debug, error, info, instrument};
2121

2222
/// Adds a package into database.
2323
///
@@ -244,6 +244,17 @@ pub(crate) async fn finish_build(
244244
debug!("updating build after finishing");
245245
let hostname = hostname::get()?;
246246

247+
let rustc_date = match parse_rustc_date(rustc_version) {
248+
Ok(date) => Some(date),
249+
Err(err) => {
250+
error!(
251+
"Failed to parse date from rustc version \"{}\": {:?}",
252+
rustc_version, err
253+
);
254+
None
255+
}
256+
};
257+
247258
let release_id = sqlx::query_scalar!(
248259
"UPDATE builds
249260
SET
@@ -252,15 +263,17 @@ pub(crate) async fn finish_build(
252263
build_status = $3,
253264
build_server = $4,
254265
errors = $5,
266+
rustc_nightly_date = $6,
255267
build_time = NOW()
256268
WHERE
257-
id = $6
269+
id = $7
258270
RETURNING rid",
259271
rustc_version,
260272
docsrs_version,
261273
build_status as BuildStatus,
262274
hostname.to_str().unwrap_or(""),
263275
errors,
276+
rustc_date,
264277
build_id,
265278
)
266279
.fetch_one(&mut *conn)
@@ -606,6 +619,7 @@ mod test {
606619
use crate::registry_api::OwnerKind;
607620
use crate::test::*;
608621
use crate::utils::CargoMetadata;
622+
use chrono::NaiveDate;
609623
use test_case::test_case;
610624

611625
#[test]
@@ -641,7 +655,55 @@ mod test {
641655
}
642656

643657
#[test]
644-
fn test_finish_build_success() {
658+
fn test_finish_build_success_valid_rustc_date() {
659+
async_wrapper(|env| async move {
660+
let mut conn = env.async_db().await.async_conn().await;
661+
let crate_id = initialize_crate(&mut conn, "krate").await?;
662+
let release_id = initialize_release(&mut conn, crate_id, "0.1.0").await?;
663+
let build_id = initialize_build(&mut conn, release_id).await?;
664+
665+
finish_build(
666+
&mut conn,
667+
build_id,
668+
"rustc 1.84.0-nightly (e7c0d2750 2024-10-15)",
669+
"docsrs_version",
670+
BuildStatus::Success,
671+
None,
672+
)
673+
.await?;
674+
675+
let row = sqlx::query!(
676+
r#"SELECT
677+
rustc_version,
678+
docsrs_version,
679+
build_status as "build_status: BuildStatus",
680+
errors,
681+
rustc_nightly_date
682+
FROM builds
683+
WHERE id = $1"#,
684+
build_id
685+
)
686+
.fetch_one(&mut *conn)
687+
.await?;
688+
689+
assert_eq!(
690+
row.rustc_version,
691+
Some("rustc 1.84.0-nightly (e7c0d2750 2024-10-15)".into())
692+
);
693+
assert_eq!(row.docsrs_version, Some("docsrs_version".into()));
694+
assert_eq!(row.build_status, BuildStatus::Success);
695+
assert_eq!(
696+
row.rustc_nightly_date,
697+
Some(NaiveDate::from_ymd_opt(2024, 10, 15).unwrap())
698+
);
699+
assert!(row.errors.is_none());
700+
701+
Ok(())
702+
})
703+
}
704+
705+
#[test]
706+
fn test_finish_build_success_invalid_rustc_date() {
645707
async_wrapper(|env| async move {
646708
let mut conn = env.async_db().await.async_conn().await;
647709
let crate_id = initialize_crate(&mut conn, "krate").await?;
@@ -663,7 +725,8 @@ mod test {
663725
rustc_version,
664726
docsrs_version,
665727
build_status as "build_status: BuildStatus",
666-
errors
728+
errors,
729+
rustc_nightly_date
667730
FROM builds
668731
WHERE id = $1"#,
669732
build_id
@@ -674,6 +737,7 @@ mod test {
674737
assert_eq!(row.rustc_version, Some("rustc_version".into()));
675738
assert_eq!(row.docsrs_version, Some("docsrs_version".into()));
676739
assert_eq!(row.build_status, BuildStatus::Success);
740+
assert!(row.rustc_nightly_date.is_none());
677741
assert!(row.errors.is_none());
678742

679743
Ok(())

src/utils/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub mod daemon;
2121
mod html;
2222
mod queue;
2323
pub(crate) mod queue_builder;
24-
mod rustc_version;
24+
pub(crate) mod rustc_version;
2525
use anyhow::Result;
2626
use serde::de::DeserializeOwned;
2727
use serde::Serialize;

src/utils/rustc_version.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn parse_rustc_version<S: AsRef<str>>(version: S) -> Result<String> {
2121
))
2222
}
2323

24-
fn parse_rustc_date<S: AsRef<str>>(version: S) -> Result<NaiveDate> {
24+
pub(crate) fn parse_rustc_date<S: AsRef<str>>(version: S) -> Result<NaiveDate> {
2525
static RE: Lazy<Regex> = Lazy::new(|| Regex::new(r" (\d+)-(\d+)-(\d+)\)$").unwrap());
2626

2727
let cap = RE

0 commit comments

Comments
 (0)