Skip to content

Commit 97f4e8e

Browse files
committed
trustpub: Add database support for trustpub_only crate restriction
1 parent d0ca089 commit 97f4e8e

File tree

8 files changed

+12
-2
lines changed

8 files changed

+12
-2
lines changed

crates/crates_io_database/src/models/krate.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub struct Crate {
3737
pub repository: Option<String>,
3838
pub max_upload_size: Option<i32>,
3939
pub max_features: Option<i16>,
40+
pub trustpub_only: bool,
4041
}
4142

4243
/// We literally never want to select `textsearchable_index_col`
@@ -52,6 +53,7 @@ type AllColumns = (
5253
crates::repository,
5354
crates::max_upload_size,
5455
crates::max_features,
56+
crates::trustpub_only,
5557
);
5658

5759
pub const ALL_COLUMNS: AllColumns = (
@@ -65,6 +67,7 @@ pub const ALL_COLUMNS: AllColumns = (
6567
crates::repository,
6668
crates::max_upload_size,
6769
crates::max_features,
70+
crates::trustpub_only,
6871
);
6972

7073
pub const MAX_NAME_LENGTH: usize = 64;

crates/crates_io_database/src/schema.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ diesel::table! {
374374
///
375375
/// (Automatically generated by Diesel.)
376376
textsearchable_index_col -> Tsvector,
377+
/// When true, this crate can only be published via Trusted Publishing, not with API tokens
378+
trustpub_only -> Bool,
377379
/// The `updated_at` column of the `crates` table.
378380
///
379381
/// Its SQL type is `Timestamptz`.

crates/crates_io_database_dump/src/dump-db.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ textsearchable_index_col = "private" # This Postgres specific and can be derived
9292
repository = "public"
9393
max_upload_size = "public"
9494
max_features = "public"
95+
trustpub_only = "public"
9596

9697
[crates_categories]
9798
dependencies = ["categories", "crates"]

crates/crates_io_database_dump/src/snapshots/crates_io_database_dump__tests__sql_scripts@export.sql.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ BEGIN ISOLATION LEVEL REPEATABLE READ, READ ONLY;
66

77
\copy "categories" ("category", "crates_cnt", "created_at", "description", "id", "path", "slug") TO 'data/categories.csv' WITH CSV HEADER
88
\copy "crate_downloads" ("crate_id", "downloads") TO 'data/crate_downloads.csv' WITH CSV HEADER
9-
\copy "crates" ("created_at", "description", "documentation", "homepage", "id", "max_features", "max_upload_size", "name", "readme", "repository", "updated_at") TO 'data/crates.csv' WITH CSV HEADER
9+
\copy "crates" ("created_at", "description", "documentation", "homepage", "id", "max_features", "max_upload_size", "name", "readme", "repository", "trustpub_only", "updated_at") TO 'data/crates.csv' WITH CSV HEADER
1010
\copy "keywords" ("crates_cnt", "created_at", "id", "keyword") TO 'data/keywords.csv' WITH CSV HEADER
1111
\copy "metadata" ("total_downloads") TO 'data/metadata.csv' WITH CSV HEADER
1212
\copy "reserved_crate_names" ("name") TO 'data/reserved_crate_names.csv' WITH CSV HEADER

crates/crates_io_database_dump/src/snapshots/crates_io_database_dump__tests__sql_scripts@import.sql.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ BEGIN;
5050

5151
\copy "categories" ("category", "crates_cnt", "created_at", "description", "id", "path", "slug") FROM 'data/categories.csv' WITH CSV HEADER
5252
\copy "crate_downloads" ("crate_id", "downloads") FROM 'data/crate_downloads.csv' WITH CSV HEADER
53-
\copy "crates" ("created_at", "description", "documentation", "homepage", "id", "max_features", "max_upload_size", "name", "readme", "repository", "updated_at") FROM 'data/crates.csv' WITH CSV HEADER
53+
\copy "crates" ("created_at", "description", "documentation", "homepage", "id", "max_features", "max_upload_size", "name", "readme", "repository", "trustpub_only", "updated_at") FROM 'data/crates.csv' WITH CSV HEADER
5454
\copy "keywords" ("crates_cnt", "created_at", "id", "keyword") FROM 'data/keywords.csv' WITH CSV HEADER
5555
\copy "metadata" ("total_downloads") FROM 'data/metadata.csv' WITH CSV HEADER
5656
\copy "reserved_crate_names" ("name") FROM 'data/reserved_crate_names.csv' WITH CSV HEADER
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE crates DROP COLUMN trustpub_only;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE crates ADD COLUMN trustpub_only BOOLEAN NOT NULL DEFAULT FALSE;
2+
COMMENT ON COLUMN crates.trustpub_only IS 'When true, this crate can only be published via Trusted Publishing, not with API tokens';

src/controllers/trustpub/emails.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ mod tests {
7979
repository: None,
8080
max_upload_size: None,
8181
max_features: None,
82+
trustpub_only: false,
8283
}
8384
}
8485

0 commit comments

Comments
 (0)