Skip to content

Commit 735558c

Browse files
committed
database: Create oidc_tokens table
1 parent 27f0366 commit 735558c

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

crates/crates_io_database/src/schema.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,22 @@ diesel::table! {
629629
}
630630
}
631631

632+
diesel::table! {
633+
/// Temporary access tokens for OIDC-based publishing (aka. Trusted Publishing)
634+
oidc_tokens (id) {
635+
/// Unique identifier of the `oidc_tokens` row
636+
id -> Int8,
637+
/// Unique identifier of the crate that can be published using this token
638+
crate_id -> Int4,
639+
/// SHA256 hash of the token that can be used to publish the crate
640+
hashed_token -> Bytea,
641+
/// Date and time when the token was created
642+
created_at -> Timestamptz,
643+
/// Date and time when the token will expire
644+
expires_at -> Timestamptz,
645+
}
646+
}
647+
632648
diesel::table! {
633649
/// List of all processed CDN log files, used to avoid processing the same file multiple times.
634650
processed_log_files (path) {
@@ -1089,6 +1105,7 @@ diesel::joinable!(emails -> users (user_id));
10891105
diesel::joinable!(follows -> crates (crate_id));
10901106
diesel::joinable!(follows -> users (user_id));
10911107
diesel::joinable!(github_oidc_configs -> crates (crate_id));
1108+
diesel::joinable!(oidc_tokens -> crates (crate_id));
10921109
diesel::joinable!(publish_limit_buckets -> users (user_id));
10931110
diesel::joinable!(publish_rate_overrides -> users (user_id));
10941111
diesel::joinable!(readme_renderings -> versions (version_id));
@@ -1119,6 +1136,7 @@ diesel::allow_tables_to_appear_in_same_query!(
11191136
github_oidc_configs,
11201137
keywords,
11211138
metadata,
1139+
oidc_tokens,
11221140
processed_log_files,
11231141
publish_limit_buckets,
11241142
publish_rate_overrides,

crates/crates_io_database_dump/src/dump-db.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ created_at = "public"
169169
[metadata.columns]
170170
total_downloads = "public"
171171

172+
[oidc_tokens]
173+
dependencies = ["crates"]
174+
[oidc_tokens.columns]
175+
id = "private"
176+
crate_id = "private"
177+
hashed_token = "private"
178+
created_at = "private"
179+
expires_at = "private"
180+
172181
[processed_log_files.columns]
173182
path = "private"
174183
time = "private"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
drop table oidc_tokens;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
create table oidc_tokens
2+
(
3+
id bigserial primary key,
4+
crate_id int not null references crates on delete cascade,
5+
hashed_token bytea not null,
6+
created_at timestamptz not null default now(),
7+
expires_at timestamptz not null
8+
);
9+
10+
comment on table oidc_tokens is 'Temporary access tokens for OIDC-based publishing (aka. Trusted Publishing)';
11+
comment on column oidc_tokens.id is 'Unique identifier of the `oidc_tokens` row';
12+
comment on column oidc_tokens.crate_id is 'Unique identifier of the crate that can be published using this token';
13+
comment on column oidc_tokens.hashed_token is 'SHA256 hash of the token that can be used to publish the crate';
14+
comment on column oidc_tokens.created_at is 'Date and time when the token was created';
15+
comment on column oidc_tokens.expires_at is 'Date and time when the token will expire';
16+
17+
create unique index oidc_tokens_crate_id_hashed_token_uindex
18+
on oidc_tokens (crate_id, hashed_token);

0 commit comments

Comments
 (0)