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;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
source: src/tests/krate/publish/edition.rs
3+
expression: response.json()
4+
snapshot_kind: text
5+
---
6+
{
7+
"version": {
8+
"audit_actions": [
9+
{
10+
"action": "publish",
11+
"time": "[datetime]",
12+
"user": {
13+
"avatar": null,
14+
"id": "[id]",
15+
"login": "foo",
16+
"name": null,
17+
"url": "https://github.com/foo"
18+
}
19+
}
20+
],
21+
"bin_names": [],
22+
"checksum": "7bca599a373dd56631d8c47704f17d2c166e75ffc7327c6dcc54c91e3d290e5b",
23+
"crate": "foo",
24+
"crate_size": 169,
25+
"created_at": "[datetime]",
26+
"dl_path": "/api/v1/crates/foo/1.0.0/download",
27+
"downloads": 0,
28+
"edition": "2021",
29+
"features": {},
30+
"has_lib": false,
31+
"id": "[id]",
32+
"lib_links": null,
33+
"license": "MIT",
34+
"links": {
35+
"authors": "/api/v1/crates/foo/1.0.0/authors",
36+
"dependencies": "/api/v1/crates/foo/1.0.0/dependencies",
37+
"version_downloads": "/api/v1/crates/foo/1.0.0/downloads"
38+
},
39+
"num": "1.0.0",
40+
"published_by": {
41+
"avatar": null,
42+
"id": "[id]",
43+
"login": "foo",
44+
"name": null,
45+
"url": "https://github.com/foo"
46+
},
47+
"readme_path": "/api/v1/crates/foo/1.0.0/readme",
48+
"rust_version": "1.0",
49+
"updated_at": "[datetime]",
50+
"yank_message": null,
51+
"yanked": false
52+
}
53+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
source: src/tests/krate/publish/edition.rs
3+
expression: response.json()
4+
snapshot_kind: text
5+
---
6+
{
7+
"crate": {
8+
"badges": [],
9+
"categories": null,
10+
"created_at": "[datetime]",
11+
"default_version": "1.0.0",
12+
"description": "description",
13+
"documentation": null,
14+
"downloads": 0,
15+
"exact_match": false,
16+
"homepage": null,
17+
"id": "foo",
18+
"keywords": null,
19+
"links": {
20+
"owner_team": "/api/v1/crates/foo/owner_team",
21+
"owner_user": "/api/v1/crates/foo/owner_user",
22+
"owners": "/api/v1/crates/foo/owners",
23+
"reverse_dependencies": "/api/v1/crates/foo/reverse_dependencies",
24+
"version_downloads": "/api/v1/crates/foo/downloads",
25+
"versions": "/api/v1/crates/foo/versions"
26+
},
27+
"max_stable_version": "1.0.0",
28+
"max_version": "1.0.0",
29+
"name": "foo",
30+
"newest_version": "1.0.0",
31+
"recent_downloads": null,
32+
"repository": null,
33+
"updated_at": "[datetime]",
34+
"versions": null,
35+
"yanked": false
36+
},
37+
"warnings": {
38+
"invalid_badges": [],
39+
"invalid_categories": [],
40+
"other": []
41+
}
42+
}

src/tests/krate/publish/snapshots/crates_io__tests__krate__publish__links__crate_with_links_field-2.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ snapshot_kind: text
2525
"created_at": "[datetime]",
2626
"dl_path": "/api/v1/crates/foo/1.0.0/download",
2727
"downloads": 0,
28+
"edition": null,
2829
"features": {},
2930
"has_lib": false,
3031
"id": "[id]",

src/tests/krate/publish/snapshots/crates_io__tests__krate__publish__manifest__boolean_readme-2.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ snapshot_kind: text
2525
"created_at": "[datetime]",
2626
"dl_path": "/api/v1/crates/foo/1.0.0/download",
2727
"downloads": 0,
28+
"edition": null,
2829
"features": {},
2930
"has_lib": false,
3031
"id": "[id]",

src/tests/krate/publish/snapshots/crates_io__tests__krate__publish__manifest__lib_and_bin_crate-2.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ snapshot_kind: text
2828
"created_at": "[datetime]",
2929
"dl_path": "/api/v1/crates/foo/1.0.0/download",
3030
"downloads": 0,
31+
"edition": null,
3132
"features": {},
3233
"has_lib": true,
3334
"id": "[id]",

src/tests/krate/snapshots/crates_io__tests__krate__yanking__patch_version_yank_unyank-2.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ snapshot_kind: text
5858
"checksum": "ddfc395ab340f413ee1d1ed0afce51a7c9df1c99c551fed5aef76edd4abe4048",
5959
"rust_version": null,
6060
"has_lib": false,
61-
"bin_names": []
61+
"bin_names": [],
62+
"edition": null
6263
}
6364
}

src/tests/krate/snapshots/crates_io__tests__krate__yanking__patch_version_yank_unyank-3.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ snapshot_kind: text
6969
"checksum": "ddfc395ab340f413ee1d1ed0afce51a7c9df1c99c551fed5aef76edd4abe4048",
7070
"rust_version": null,
7171
"has_lib": false,
72-
"bin_names": []
72+
"bin_names": [],
73+
"edition": null
7374
}
7475
}

src/tests/krate/snapshots/crates_io__tests__krate__yanking__patch_version_yank_unyank-4.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ snapshot_kind: text
6969
"checksum": "ddfc395ab340f413ee1d1ed0afce51a7c9df1c99c551fed5aef76edd4abe4048",
7070
"rust_version": null,
7171
"has_lib": false,
72-
"bin_names": []
72+
"bin_names": [],
73+
"edition": null
7374
}
7475
}

src/tests/krate/snapshots/crates_io__tests__krate__yanking__patch_version_yank_unyank-5.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ snapshot_kind: text
8080
"checksum": "ddfc395ab340f413ee1d1ed0afce51a7c9df1c99c551fed5aef76edd4abe4048",
8181
"rust_version": null,
8282
"has_lib": false,
83-
"bin_names": []
83+
"bin_names": [],
84+
"edition": null
8485
}
8586
}

src/tests/krate/snapshots/crates_io__tests__krate__yanking__patch_version_yank_unyank-6.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ snapshot_kind: text
8080
"checksum": "ddfc395ab340f413ee1d1ed0afce51a7c9df1c99c551fed5aef76edd4abe4048",
8181
"rust_version": null,
8282
"has_lib": false,
83-
"bin_names": []
83+
"bin_names": [],
84+
"edition": null
8485
}
8586
}

src/tests/krate/snapshots/crates_io__tests__krate__yanking__patch_version_yank_unyank.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ snapshot_kind: text
5858
"checksum": "ddfc395ab340f413ee1d1ed0afce51a7c9df1c99c551fed5aef76edd4abe4048",
5959
"rust_version": null,
6060
"has_lib": false,
61-
"bin_names": []
61+
"bin_names": [],
62+
"edition": null
6263
}
6364
}

src/tests/routes/crates/snapshots/crates_io__tests__routes__crates__read__show.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ snapshot_kind: text
5959
"created_at": "[datetime]",
6060
"dl_path": "/api/v1/crates/foo_show/1.0.0/download",
6161
"downloads": 0,
62+
"edition": null,
6263
"features": {},
6364
"has_lib": null,
6465
"id": 1,
@@ -86,6 +87,7 @@ snapshot_kind: text
8687
"created_at": "[datetime]",
8788
"dl_path": "/api/v1/crates/foo_show/0.5.1/download",
8889
"downloads": 0,
90+
"edition": null,
8991
"features": {},
9092
"has_lib": null,
9193
"id": 3,
@@ -119,6 +121,7 @@ snapshot_kind: text
119121
"created_at": "[datetime]",
120122
"dl_path": "/api/v1/crates/foo_show/0.5.0/download",
121123
"downloads": 0,
124+
"edition": null,
122125
"features": {},
123126
"has_lib": null,
124127
"id": 2,

src/tests/routes/crates/snapshots/crates_io__tests__routes__crates__read__show_all_yanked.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ snapshot_kind: text
5858
"created_at": "[datetime]",
5959
"dl_path": "/api/v1/crates/foo_show/1.0.0/download",
6060
"downloads": 0,
61+
"edition": null,
6162
"features": {},
6263
"has_lib": null,
6364
"id": 1,
@@ -91,6 +92,7 @@ snapshot_kind: text
9192
"created_at": "[datetime]",
9293
"dl_path": "/api/v1/crates/foo_show/0.5.0/download",
9394
"downloads": 0,
95+
"edition": null,
9496
"features": {},
9597
"has_lib": null,
9698
"id": 2,

src/tests/routes/crates/snapshots/crates_io__tests__routes__crates__reverse_dependencies__prerelease_versions_not_included_in_reverse_dependencies.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ snapshot_kind: text
3131
"created_at": "[datetime]",
3232
"dl_path": "/api/v1/crates/c3/1.0.0/download",
3333
"downloads": 0,
34+
"edition": null,
3435
"features": {},
3536
"has_lib": null,
3637
"id": 3,

src/tests/routes/crates/snapshots/crates_io__tests__routes__crates__reverse_dependencies__reverse_dependencies.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ snapshot_kind: text
3131
"created_at": "[datetime]",
3232
"dl_path": "/api/v1/crates/c2/1.1.0/download",
3333
"downloads": 0,
34+
"edition": null,
3435
"features": {},
3536
"has_lib": null,
3637
"id": 3,

src/tests/routes/crates/snapshots/crates_io__tests__routes__crates__reverse_dependencies__reverse_dependencies_includes_published_by_user_when_present.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ snapshot_kind: text
4343
"created_at": "[datetime]",
4444
"dl_path": "/api/v1/crates/c3/3.0.0/download",
4545
"downloads": 0,
46+
"edition": null,
4647
"features": {},
4748
"has_lib": null,
4849
"id": 3,
@@ -76,6 +77,7 @@ snapshot_kind: text
7677
"created_at": "[datetime]",
7778
"dl_path": "/api/v1/crates/c2/2.0.0/download",
7879
"downloads": 0,
80+
"edition": null,
7981
"features": {},
8082
"has_lib": null,
8183
"id": 2,

src/tests/routes/crates/snapshots/crates_io__tests__routes__crates__reverse_dependencies__reverse_dependencies_query_supports_u64_version_number_parts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ snapshot_kind: text
3131
"created_at": "[datetime]",
3232
"dl_path": "/api/v1/crates/c2/1.0.18446744073709551615/download",
3333
"downloads": 0,
34+
"edition": null,
3435
"features": {},
3536
"has_lib": null,
3637
"id": 2,

src/tests/routes/crates/snapshots/crates_io__tests__routes__crates__reverse_dependencies__reverse_dependencies_when_old_version_doesnt_depend_but_new_does.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ snapshot_kind: text
3131
"created_at": "[datetime]",
3232
"dl_path": "/api/v1/crates/c2/2.0.0/download",
3333
"downloads": 0,
34+
"edition": null,
3435
"features": {},
3536
"has_lib": null,
3637
"id": 3,

0 commit comments

Comments
 (0)