Labrinth ID cleanup (#3681)

* Put all ID types in the labrinth::models::ids, and reduce code duplication with them

* Rewrite labrinth::database::models::ids and rename most DB interface ID structs to be prefixed with DB

* Run sqlx prepare

---------

Co-authored-by: Alejandro González <7822554+AlexTMjugador@users.noreply.github.com>
This commit is contained in:
Josiah Glosson
2025-05-22 03:34:36 -05:00
committed by GitHub
parent c6022ad977
commit 9e527ff141
111 changed files with 1477 additions and 1965 deletions

View File

@@ -15,7 +15,7 @@ const ORGANIZATIONS_TITLES_NAMESPACE: &str = "organizations_titles";
/// An organization of users who together control one or more projects and organizations.
pub struct Organization {
/// The id of the organization
pub id: OrganizationId,
pub id: DBOrganizationId,
/// The slug of the organization
pub slug: String,
@@ -24,7 +24,7 @@ pub struct Organization {
pub name: String,
/// The associated team of the organization
pub team_id: TeamId,
pub team_id: DBTeamId,
/// The description of the organization
pub description: String,
@@ -48,7 +48,7 @@ impl Organization {
self.id.0,
self.slug,
self.name,
self.team_id as TeamId,
self.team_id as DBTeamId,
self.description,
self.icon_url,
self.raw_icon_url,
@@ -74,7 +74,7 @@ impl Organization {
}
pub async fn get_id<'a, 'b, E>(
id: OrganizationId,
id: DBOrganizationId,
exec: E,
redis: &RedisPool,
) -> Result<Option<Self>, super::DatabaseError>
@@ -87,7 +87,7 @@ impl Organization {
}
pub async fn get_many_ids<'a, 'b, E>(
organization_ids: &[OrganizationId],
organization_ids: &[DBOrganizationId],
exec: E,
redis: &RedisPool,
) -> Result<Vec<Self>, super::DatabaseError>
@@ -143,10 +143,10 @@ impl Organization {
.fetch(exec)
.try_fold(DashMap::new(), |acc, m| {
let org = Organization {
id: OrganizationId(m.id),
id: DBOrganizationId(m.id),
slug: m.slug.clone(),
name: m.name,
team_id: TeamId(m.team_id),
team_id: DBTeamId(m.team_id),
description: m.description,
icon_url: m.icon_url,
raw_icon_url: m.raw_icon_url,
@@ -168,7 +168,7 @@ impl Organization {
// Gets organization associated with a project ID, if it exists and there is one
pub async fn get_associated_organization_project_id<'a, 'b, E>(
project_id: ProjectId,
project_id: DBProjectId,
exec: E,
) -> Result<Option<Self>, super::DatabaseError>
where
@@ -182,17 +182,17 @@ impl Organization {
WHERE m.id = $1
GROUP BY o.id;
",
project_id as ProjectId,
project_id as DBProjectId,
)
.fetch_optional(exec)
.await?;
if let Some(result) = result {
Ok(Some(Organization {
id: OrganizationId(result.id),
id: DBOrganizationId(result.id),
slug: result.slug,
name: result.name,
team_id: TeamId(result.team_id),
team_id: DBTeamId(result.team_id),
description: result.description,
icon_url: result.icon_url,
raw_icon_url: result.raw_icon_url,
@@ -204,7 +204,7 @@ impl Organization {
}
pub async fn remove(
id: OrganizationId,
id: DBOrganizationId,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
redis: &RedisPool,
) -> Result<Option<()>, super::DatabaseError> {
@@ -216,7 +216,7 @@ impl Organization {
DELETE FROM organizations
WHERE id = $1
",
id as OrganizationId,
id as DBOrganizationId,
)
.execute(&mut **transaction)
.await?;
@@ -228,7 +228,7 @@ impl Organization {
DELETE FROM team_members
WHERE team_id = $1
",
organization.team_id as TeamId,
organization.team_id as DBTeamId,
)
.execute(&mut **transaction)
.await?;
@@ -238,7 +238,7 @@ impl Organization {
DELETE FROM teams
WHERE id = $1
",
organization.team_id as TeamId,
organization.team_id as DBTeamId,
)
.execute(&mut **transaction)
.await?;
@@ -250,7 +250,7 @@ impl Organization {
}
pub async fn clear_cache(
id: OrganizationId,
id: DBOrganizationId,
slug: Option<String>,
redis: &RedisPool,
) -> Result<(), super::DatabaseError> {