Skip to content

Commit

Permalink
Merge pull request #9998 from Turbo87/more-version-columns
Browse files Browse the repository at this point in the history
Add description, homepage, documentation and repository fields for versions
  • Loading branch information
Turbo87 authored Nov 26, 2024
2 parents 40bb88f + 1da5646 commit 154e004
Show file tree
Hide file tree
Showing 30 changed files with 175 additions and 12 deletions.
8 changes: 8 additions & 0 deletions crates/crates_io_database/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,14 @@ diesel::table! {
num_no_build -> Varchar,
/// The declared Rust Edition required to compile this version of the crate.
edition -> Nullable<Text>,
/// Value of the `description` field in the `Cargo.toml` file of this version.
description -> Nullable<Text>,
/// Value of the `homepage` field in the `Cargo.toml` file of this version.
homepage -> Nullable<Text>,
/// Value of the `documentation` field in the `Cargo.toml` file of this version.
documentation -> Nullable<Text>,
/// Value of the `repository` field in the `Cargo.toml` file of this version.
repository -> Nullable<Text>,
}
}

Expand Down
4 changes: 4 additions & 0 deletions crates/crates_io_database_dump/src/dump-db.toml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ has_lib = "public"
bin_names = "public"
yank_message = "private"
edition = "public"
description = "public"
homepage = "public"
documentation = "public"
repository = "public"

[versions_published_by.columns]
version_id = "private"
Expand Down
2 changes: 1 addition & 1 deletion ...o_database_dump/src/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ BEGIN ISOLATION LEVEL REPEATABLE READ, READ ONLY;
\copy "crates_keywords" ("crate_id", "keyword_id") TO 'data/crates_keywords.csv' WITH CSV HEADER
\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

\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
\copy "versions" ("bin_names", "checksum", "crate_id", "crate_size", "created_at", "description", "documentation", "downloads", "edition", "features", "has_lib", "homepage", "id", "license", "links", "num", "published_by", "repository", "rust_version", "updated_at", "yanked") TO 'data/versions.csv' WITH CSV HEADER
\copy "default_versions" ("crate_id", "version_id") TO 'data/default_versions.csv' WITH CSV HEADER
\copy "dependencies" ("crate_id", "default_features", "explicit_name", "features", "id", "kind", "optional", "req", "target", "version_id") TO 'data/dependencies.csv' WITH CSV HEADER
\copy "version_downloads" ("date", "downloads", "version_id") TO 'data/version_downloads.csv' WITH CSV HEADER
Expand Down
2 changes: 1 addition & 1 deletion ...o_database_dump/src/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ BEGIN;
\copy "crates_categories" ("category_id", "crate_id") FROM 'data/crates_categories.csv' WITH CSV HEADER
\copy "crates_keywords" ("crate_id", "keyword_id") FROM 'data/crates_keywords.csv' WITH CSV HEADER
\copy "crate_owners" ("crate_id", "created_at", "created_by", "owner_id", "owner_kind") FROM 'data/crate_owners.csv' WITH CSV HEADER
\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
\copy "versions" ("bin_names", "checksum", "crate_id", "crate_size", "created_at", "description", "documentation", "downloads", "edition", "features", "has_lib", "homepage", "id", "license", "links", "num", "published_by", "repository", "rust_version", "updated_at", "yanked") FROM 'data/versions.csv' WITH CSV HEADER
\copy "default_versions" ("crate_id", "version_id") FROM 'data/default_versions.csv' WITH CSV HEADER
\copy "dependencies" ("crate_id", "default_features", "explicit_name", "features", "id", "kind", "optional", "req", "target", "version_id") FROM 'data/dependencies.csv' WITH CSV HEADER
\copy "version_downloads" ("date", "downloads", "version_id") FROM 'data/version_downloads.csv' WITH CSV HEADER
Expand Down
5 changes: 5 additions & 0 deletions migrations/2024-11-19-095931_add-version-columns/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
alter table versions
drop column description,
drop column homepage,
drop column documentation,
drop column repository;
10 changes: 10 additions & 0 deletions migrations/2024-11-19-095931_add-version-columns/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
alter table versions
add column description text,
add column homepage text,
add column documentation text,
add column repository text;

comment on column versions.description is 'Value of the `description` field in the `Cargo.toml` file of this version.';
comment on column versions.homepage is 'Value of the `homepage` field in the `Cargo.toml` file of this version.';
comment on column versions.documentation is 'Value of the `documentation` field in the `Cargo.toml` file of this version.';
comment on column versions.repository is 'Value of the `repository` field in the `Cargo.toml` file of this version.';
12 changes: 8 additions & 4 deletions src/controllers/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra

if let Some(deleted_crate) = deleted_crate {
return Err(bad_request(format!(
"A crate with the name `{}` was recently deleted. Reuse of this name will be available after {}.",
deleted_crate.0,
deleted_crate.1.to_rfc3339_opts(SecondsFormat::Secs, true)
)));
"A crate with the name `{}` was recently deleted. Reuse of this name will be available after {}.",
deleted_crate.0,
deleted_crate.1.to_rfc3339_opts(SecondsFormat::Secs, true)
)));
}

// this query should only be used for the endpoint scope calculation
Expand Down Expand Up @@ -394,6 +394,10 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
.has_lib(tarball_info.manifest.lib.is_some())
.bin_names(bin_names.as_slice())
.maybe_edition(edition)
.maybe_description(description.as_deref())
.maybe_homepage(homepage.as_deref())
.maybe_documentation(documentation.as_deref())
.maybe_repository(repository.as_deref())
.build();

let version = new_version.save(conn, &verified_email_address).await.map_err(|error| {
Expand Down
8 changes: 8 additions & 0 deletions src/models/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ pub struct Version {
pub yank_message: Option<String>,
pub num_no_build: String,
pub edition: Option<String>,
pub description: Option<String>,
pub homepage: Option<String>,
pub documentation: Option<String>,
pub repository: Option<String>,
}

impl Version {
Expand Down Expand Up @@ -95,6 +99,10 @@ pub struct NewVersion<'a> {
pub has_lib: Option<bool>,
pub bin_names: Option<&'a [&'a str]>,
edition: Option<&'a str>,
description: Option<&'a str>,
homepage: Option<&'a str>,
documentation: Option<&'a str>,
repository: Option<&'a str>,
}

impl NewVersion<'_> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ snapshot_kind: text
"crate": "foo",
"crate_size": 169,
"created_at": "[datetime]",
"description": "description",
"dl_path": "/api/v1/crates/foo/1.0.0/download",
"documentation": null,
"downloads": 0,
"edition": "2021",
"features": {},
"has_lib": false,
"homepage": null,
"id": "[id]",
"lib_links": null,
"license": "MIT",
Expand All @@ -45,6 +48,7 @@ snapshot_kind: text
"url": "https://github.com/foo"
},
"readme_path": "/api/v1/crates/foo/1.0.0/readme",
"repository": null,
"rust_version": "1.0",
"updated_at": "[datetime]",
"yank_message": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ snapshot_kind: text
"crate": "foo",
"crate_size": 162,
"created_at": "[datetime]",
"description": "foo?!",
"dl_path": "/api/v1/crates/foo/1.0.0/download",
"documentation": null,
"downloads": 0,
"edition": null,
"features": {},
"has_lib": false,
"homepage": null,
"id": "[id]",
"lib_links": "git2",
"license": "MIT",
Expand All @@ -45,6 +48,7 @@ snapshot_kind: text
"url": "https://github.com/foo"
},
"readme_path": "/api/v1/crates/foo/1.0.0/readme",
"repository": null,
"rust_version": null,
"updated_at": "[datetime]",
"yank_message": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ snapshot_kind: text
"crate": "foo",
"crate_size": 170,
"created_at": "[datetime]",
"description": "description",
"dl_path": "/api/v1/crates/foo/1.0.0/download",
"documentation": null,
"downloads": 0,
"edition": null,
"features": {},
"has_lib": false,
"homepage": null,
"id": "[id]",
"lib_links": null,
"license": "MIT",
Expand All @@ -45,6 +48,7 @@ snapshot_kind: text
"url": "https://github.com/foo"
},
"readme_path": "/api/v1/crates/foo/1.0.0/readme",
"repository": null,
"rust_version": "1.69",
"updated_at": "[datetime]",
"yank_message": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ snapshot_kind: text
"crate": "foo",
"crate_size": 241,
"created_at": "[datetime]",
"description": "description",
"dl_path": "/api/v1/crates/foo/1.0.0/download",
"documentation": null,
"downloads": 0,
"edition": null,
"features": {},
"has_lib": true,
"homepage": null,
"id": "[id]",
"lib_links": null,
"license": "MIT",
Expand All @@ -48,6 +51,7 @@ snapshot_kind: text
"url": "https://github.com/foo"
},
"readme_path": "/api/v1/crates/foo/1.0.0/readme",
"repository": null,
"rust_version": null,
"updated_at": "[datetime]",
"yank_message": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ snapshot_kind: text
"rust_version": null,
"has_lib": false,
"bin_names": [],
"edition": null
"edition": null,
"description": "description",
"homepage": null,
"documentation": null,
"repository": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ snapshot_kind: text
"rust_version": null,
"has_lib": false,
"bin_names": [],
"edition": null
"edition": null,
"description": "description",
"homepage": null,
"documentation": null,
"repository": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ snapshot_kind: text
"rust_version": null,
"has_lib": false,
"bin_names": [],
"edition": null
"edition": null,
"description": "description",
"homepage": null,
"documentation": null,
"repository": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ snapshot_kind: text
"rust_version": null,
"has_lib": false,
"bin_names": [],
"edition": null
"edition": null,
"description": "description",
"homepage": null,
"documentation": null,
"repository": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ snapshot_kind: text
"rust_version": null,
"has_lib": false,
"bin_names": [],
"edition": null
"edition": null,
"description": "description",
"homepage": null,
"documentation": null,
"repository": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ snapshot_kind: text
"rust_version": null,
"has_lib": false,
"bin_names": [],
"edition": null
"edition": null,
"description": "description",
"homepage": null,
"documentation": null,
"repository": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ snapshot_kind: text
"crate": "foo_show",
"crate_size": 0,
"created_at": "[datetime]",
"description": null,
"dl_path": "/api/v1/crates/foo_show/1.0.0/download",
"documentation": null,
"downloads": 0,
"edition": null,
"features": {},
"has_lib": null,
"homepage": null,
"id": 1,
"lib_links": null,
"license": null,
Expand All @@ -73,6 +76,7 @@ snapshot_kind: text
"num": "1.0.0",
"published_by": null,
"readme_path": "/api/v1/crates/foo_show/1.0.0/readme",
"repository": null,
"rust_version": null,
"updated_at": "[datetime]",
"yank_message": null,
Expand All @@ -85,11 +89,14 @@ snapshot_kind: text
"crate": "foo_show",
"crate_size": 0,
"created_at": "[datetime]",
"description": null,
"dl_path": "/api/v1/crates/foo_show/0.5.1/download",
"documentation": null,
"downloads": 0,
"edition": null,
"features": {},
"has_lib": null,
"homepage": null,
"id": 3,
"lib_links": null,
"license": null,
Expand All @@ -107,6 +114,7 @@ snapshot_kind: text
"url": "https://github.com/foo"
},
"readme_path": "/api/v1/crates/foo_show/0.5.1/readme",
"repository": null,
"rust_version": null,
"updated_at": "[datetime]",
"yank_message": null,
Expand All @@ -119,11 +127,14 @@ snapshot_kind: text
"crate": "foo_show",
"crate_size": 0,
"created_at": "[datetime]",
"description": null,
"dl_path": "/api/v1/crates/foo_show/0.5.0/download",
"documentation": null,
"downloads": 0,
"edition": null,
"features": {},
"has_lib": null,
"homepage": null,
"id": 2,
"lib_links": null,
"license": null,
Expand All @@ -141,6 +152,7 @@ snapshot_kind: text
"url": "https://github.com/foo"
},
"readme_path": "/api/v1/crates/foo_show/0.5.0/readme",
"repository": null,
"rust_version": null,
"updated_at": "[datetime]",
"yank_message": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ snapshot_kind: text
"crate": "foo_show",
"crate_size": 0,
"created_at": "[datetime]",
"description": null,
"dl_path": "/api/v1/crates/foo_show/1.0.0/download",
"documentation": null,
"downloads": 0,
"edition": null,
"features": {},
"has_lib": null,
"homepage": null,
"id": 1,
"lib_links": null,
"license": null,
Expand All @@ -78,6 +81,7 @@ snapshot_kind: text
"url": "https://github.com/foo"
},
"readme_path": "/api/v1/crates/foo_show/1.0.0/readme",
"repository": null,
"rust_version": null,
"updated_at": "[datetime]",
"yank_message": null,
Expand All @@ -90,11 +94,14 @@ snapshot_kind: text
"crate": "foo_show",
"crate_size": 0,
"created_at": "[datetime]",
"description": null,
"dl_path": "/api/v1/crates/foo_show/0.5.0/download",
"documentation": null,
"downloads": 0,
"edition": null,
"features": {},
"has_lib": null,
"homepage": null,
"id": 2,
"lib_links": null,
"license": null,
Expand All @@ -112,6 +119,7 @@ snapshot_kind: text
"url": "https://github.com/foo"
},
"readme_path": "/api/v1/crates/foo_show/0.5.0/readme",
"repository": null,
"rust_version": null,
"updated_at": "[datetime]",
"yank_message": null,
Expand Down
Loading

0 comments on commit 154e004

Please sign in to comment.