Skip to content

Commit a1b9583

Browse files
authored
Merge pull request #9932 from Turbo87/edition-column
Add `versions.edition` column to the database and expose it on the API
2 parents 88f856d + 934d3fb commit a1b9583

File tree

33 files changed

+187
-8
lines changed

33 files changed

+187
-8
lines changed

crates/crates_io_database/src/schema.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,8 @@ diesel::table! {
10111011
yank_message -> Nullable<Text>,
10121012
/// This is the same as `num` without the optional "build metadata" part (except for some versions that were published before we started validating this).
10131013
num_no_build -> Varchar,
1014+
/// The declared Rust Edition required to compile this version of the crate.
1015+
edition -> Nullable<Text>,
10141016
}
10151017
}
10161018

crates/crates_io_database_dump/src/dump-db.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ rust_version = "public"
246246
has_lib = "public"
247247
bin_names = "public"
248248
yank_message = "private"
249+
edition = "public"
249250

250251
[versions_published_by.columns]
251252
version_id = "private"

crates/crates_io_database_dump/src/snapshots/[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ BEGIN ISOLATION LEVEL REPEATABLE READ, READ ONLY;
1818
\copy "crates_keywords" ("crate_id", "keyword_id") TO 'data/crates_keywords.csv' WITH CSV HEADER
1919
\copy (SELECT "crate_id", "created_at", "created_by", "owner_id", "owner_kind" FROM "crate_owners" WHERE NOT deleted) TO 'data/crate_owners.csv' WITH CSV HEADER
2020

21-
\copy "versions" ("bin_names", "checksum", "crate_id", "crate_size", "created_at", "downloads", "features", "has_lib", "id", "license", "links", "num", "published_by", "rust_version", "updated_at", "yanked") TO 'data/versions.csv' WITH CSV HEADER
21+
\copy "versions" ("bin_names", "checksum", "crate_id", "crate_size", "created_at", "downloads", "edition", "features", "has_lib", "id", "license", "links", "num", "published_by", "rust_version", "updated_at", "yanked") TO 'data/versions.csv' WITH CSV HEADER
2222
\copy "default_versions" ("crate_id", "version_id") TO 'data/default_versions.csv' WITH CSV HEADER
2323
\copy "dependencies" ("crate_id", "default_features", "explicit_name", "features", "id", "kind", "optional", "req", "target", "version_id") TO 'data/dependencies.csv' WITH CSV HEADER
2424
\copy "version_downloads" ("date", "downloads", "version_id") TO 'data/version_downloads.csv' WITH CSV HEADER

crates/crates_io_database_dump/src/snapshots/[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ BEGIN;
6060
\copy "crates_categories" ("category_id", "crate_id") FROM 'data/crates_categories.csv' WITH CSV HEADER
6161
\copy "crates_keywords" ("crate_id", "keyword_id") FROM 'data/crates_keywords.csv' WITH CSV HEADER
6262
\copy "crate_owners" ("crate_id", "created_at", "created_by", "owner_id", "owner_kind") FROM 'data/crate_owners.csv' WITH CSV HEADER
63-
\copy "versions" ("bin_names", "checksum", "crate_id", "crate_size", "created_at", "downloads", "features", "has_lib", "id", "license", "links", "num", "published_by", "rust_version", "updated_at", "yanked") FROM 'data/versions.csv' WITH CSV HEADER
63+
\copy "versions" ("bin_names", "checksum", "crate_id", "crate_size", "created_at", "downloads", "edition", "features", "has_lib", "id", "license", "links", "num", "published_by", "rust_version", "updated_at", "yanked") FROM 'data/versions.csv' WITH CSV HEADER
6464
\copy "default_versions" ("crate_id", "version_id") FROM 'data/default_versions.csv' WITH CSV HEADER
6565
\copy "dependencies" ("crate_id", "default_features", "explicit_name", "features", "id", "kind", "optional", "req", "target", "version_id") FROM 'data/dependencies.csv' WITH CSV HEADER
6666
\copy "version_downloads" ("date", "downloads", "version_id") FROM 'data/version_downloads.csv' WITH CSV HEADER
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 edition;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
alter table versions
2+
add column edition text;
3+
4+
comment on column versions.edition is 'The declared Rust Edition required to compile this version of the crate.';

src/controllers/krate/publish.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
181181
let documentation = package.documentation.map(|it| it.as_local().unwrap());
182182
let repository = package.repository.map(|it| it.as_local().unwrap());
183183
let rust_version = package.rust_version.map(|rv| rv.as_local().unwrap());
184+
let edition = package.edition.map(|rv| rv.as_local().unwrap());
184185

185186
// Make sure required fields are provided
186187
fn empty(s: Option<&String>) -> bool {
@@ -384,6 +385,8 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
384385
.filter_map(|bin| bin.name.as_deref())
385386
.collect::<Vec<_>>();
386387

388+
let edition = edition.map(|edition| edition.as_str());
389+
387390
// Read tarball from request
388391
let hex_cksum: String = Sha256::digest(&tarball_bytes).encode_hex();
389392

@@ -400,6 +403,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
400403
.maybe_rust_version(rust_version.as_deref())
401404
.has_lib(tarball_info.manifest.lib.is_some())
402405
.bin_names(bin_names.as_slice())
406+
.maybe_edition(edition)
403407
.build();
404408

405409
let version = new_version.save(conn, &verified_email_address).map_err(|error| {

src/models/version.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub struct Version {
3333
pub bin_names: Option<Vec<Option<String>>>,
3434
pub yank_message: Option<String>,
3535
pub num_no_build: String,
36+
pub edition: Option<String>,
3637
}
3738

3839
impl Version {
@@ -96,6 +97,7 @@ pub struct NewVersion<'a> {
9697
rust_version: Option<&'a str>,
9798
pub has_lib: Option<bool>,
9899
pub bin_names: Option<&'a [&'a str]>,
100+
edition: Option<&'a str>,
99101
}
100102

101103
impl NewVersion<'_> {

src/tests/krate/publish/edition.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use crate::tests::builders::PublishBuilder;
2+
use crate::tests::util::insta::{any_id_redaction, id_redaction};
3+
use crate::tests::util::{RequestHelper, TestApp};
4+
use http::StatusCode;
5+
use insta::assert_json_snapshot;
6+
7+
#[tokio::test(flavor = "multi_thread")]
8+
async fn test_edition_is_saved() {
9+
let (_app, _, _, token) = TestApp::full().with_token().await;
10+
11+
let manifest = r#"
12+
[package]
13+
name = "foo"
14+
version = "1.0.0"
15+
description = "description"
16+
license = "MIT"
17+
edition = "2021"
18+
rust-version = "1.0"
19+
"#;
20+
let pb = PublishBuilder::new("foo", "1.0.0").custom_manifest(manifest);
21+
let response = token.publish_crate(pb).await;
22+
assert_eq!(response.status(), StatusCode::OK);
23+
assert_json_snapshot!(response.json(), {
24+
".crate.created_at" => "[datetime]",
25+
".crate.updated_at" => "[datetime]",
26+
});
27+
28+
let response = token.get::<()>("/api/v1/crates/foo/1.0.0").await;
29+
assert_eq!(response.status(), StatusCode::OK);
30+
assert_json_snapshot!(response.json(), {
31+
".version.id" => any_id_redaction(),
32+
".version.created_at" => "[datetime]",
33+
".version.updated_at" => "[datetime]",
34+
".version.published_by.id" => id_redaction(token.as_model().user_id),
35+
".version.audit_actions[].time" => "[datetime]",
36+
".version.audit_actions[].user.id" => id_redaction(token.as_model().user_id),
37+
});
38+
}

src/tests/krate/publish/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod build_metadata;
55
mod categories;
66
mod deleted_crates;
77
mod dependencies;
8+
mod edition;
89
mod emails;
910
mod features;
1011
mod git;

0 commit comments

Comments
 (0)