Skip to content

Commit 46ceb2b

Browse files
committed
Trusted Publishing: Add GitHubConfig and NewGitHubConfig data access objects
1 parent fea3aa1 commit 46ceb2b

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

crates/crates_io_database/src/models/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ pub mod krate;
3333
mod owner;
3434
pub mod team;
3535
pub mod token;
36+
pub mod trusted_publishing;
3637
pub mod user;
3738
pub mod version;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use crate::schema::trustpub_configs_github;
2+
use chrono::{DateTime, Utc};
3+
use diesel::prelude::*;
4+
use diesel_async::{AsyncPgConnection, RunQueryDsl};
5+
6+
#[derive(Debug, Identifiable, Queryable, Selectable)]
7+
#[diesel(table_name = trustpub_configs_github, check_for_backend(diesel::pg::Pg))]
8+
pub struct GitHubConfig {
9+
pub id: i32,
10+
pub crate_id: i32,
11+
pub repository_owner: String,
12+
pub repository_owner_id: i32,
13+
pub repository_name: String,
14+
pub workflow_filename: String,
15+
pub environment: Option<String>,
16+
pub created_at: DateTime<Utc>,
17+
}
18+
19+
#[derive(Debug, Insertable)]
20+
#[diesel(table_name = trustpub_configs_github, check_for_backend(diesel::pg::Pg))]
21+
pub struct NewGitHubConfig<'a> {
22+
pub crate_id: i32,
23+
pub repository_owner: &'a str,
24+
pub repository_owner_id: i32,
25+
pub repository_name: &'a str,
26+
pub workflow_filename: &'a str,
27+
pub environment: Option<&'a str>,
28+
}
29+
30+
impl NewGitHubConfig<'_> {
31+
pub async fn insert(&self, conn: &mut AsyncPgConnection) -> QueryResult<GitHubConfig> {
32+
self.insert_into(trustpub_configs_github::table)
33+
.returning(GitHubConfig::as_returning())
34+
.get_result(conn)
35+
.await
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mod github_config;
2+
3+
pub use self::github_config::{GitHubConfig, NewGitHubConfig};

0 commit comments

Comments
 (0)