Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

database: Add categories and keywords columns to the versions table #10078

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/crates_io_database/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,10 @@ diesel::table! {
documentation -> Nullable<Text>,
/// Value of the `repository` field in the `Cargo.toml` file of this version.
repository -> Nullable<Text>,
/// The list of `categories` in the `Cargo.toml` file of this version.
categories -> Array<Nullable<Text>>,
/// The list of `keywords` in the `Cargo.toml` file of this version.
keywords -> Array<Nullable<Text>>,
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/crates_io_database_dump/src/dump-db.toml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ description = "public"
homepage = "public"
documentation = "public"
repository = "public"
categories = "public"
keywords = "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", "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 "versions" ("bin_names", "categories", "checksum", "crate_id", "crate_size", "created_at", "description", "documentation", "downloads", "edition", "features", "has_lib", "homepage", "id", "keywords", "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", "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 "versions" ("bin_names", "categories", "checksum", "crate_id", "crate_size", "created_at", "description", "documentation", "downloads", "edition", "features", "has_lib", "homepage", "id", "keywords", "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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
alter table versions
drop column categories,
drop column keywords;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
alter table versions
add column categories text[] default array[]::text[] not null,
add column keywords text[] default array[]::text[] not null;

comment on column versions.categories is 'The list of `categories` in the `Cargo.toml` file of this version.';
comment on column versions.keywords is 'The list of `keywords` in the `Cargo.toml` file of this version.';
2 changes: 2 additions & 0 deletions src/controllers/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
.maybe_homepage(homepage.as_deref())
.maybe_documentation(documentation.as_deref())
.maybe_repository(repository.as_deref())
.categories(&categories)
.keywords(&keywords)
.build();

let version = new_version.save(conn, &verified_email_address).await.map_err(|error| {
Expand Down
2 changes: 2 additions & 0 deletions src/models/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ pub struct NewVersion<'a> {
homepage: Option<&'a str>,
documentation: Option<&'a str>,
repository: Option<&'a str>,
categories: Option<&'a [&'a str]>,
keywords: Option<&'a [&'a str]>,
}

impl NewVersion<'_> {
Expand Down