Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
renaming, fields
Browse files Browse the repository at this point in the history
  • Loading branch information
thesuzerain committed Nov 26, 2023
1 parent 8fab4f8 commit 83ab67d
Show file tree
Hide file tree
Showing 25 changed files with 187 additions and 282 deletions.
12 changes: 12 additions & 0 deletions migrations/20231124070100_renaming_consistency.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- rename 'title' to 'name' in all tables (collections, organizations, mods, mods_gallery, notifications, notifications_actions)
ALTER TABLE collections RENAME COLUMN title TO name;
ALTER TABLE organizations RENAME COLUMN title TO name;
ALTER TABLE mods RENAME COLUMN title TO name;
ALTER TABLE mods_gallery RENAME COLUMN title TO name;
ALTER TABLE notifications RENAME COLUMN title TO name;
ALTER TABLE notifications_actions RENAME COLUMN title TO name;

-- rename project 'description' to 'summary'
-- rename project 'body' to 'description'
ALTER TABLE mods RENAME COLUMN description TO summary;
ALTER TABLE mods RENAME COLUMN body TO description;
6 changes: 3 additions & 3 deletions src/database/models/collection_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Collection {
sqlx::query!(
"
INSERT INTO collections (
id, user_id, title, description,
id, user_id, name, description,
created, icon_url, status
)
VALUES (
Expand Down Expand Up @@ -190,7 +190,7 @@ impl Collection {
remaining_collections.iter().map(|x| x.0).collect();
let db_collections: Vec<Collection> = sqlx::query!(
"
SELECT c.id id, c.title title, c.description description,
SELECT c.id id, c.name name, c.description description,
c.icon_url icon_url, c.color color, c.created created, c.user_id user_id,
c.updated updated, c.status status,
ARRAY_AGG(DISTINCT cm.mod_id) filter (where cm.mod_id is not null) mods
Expand All @@ -209,7 +209,7 @@ impl Collection {
Collection {
id: CollectionId(id),
user_id: UserId(m.user_id),
name: m.title.clone(),
name: m.name.clone(),
description: m.description.clone(),
icon_url: m.icon_url.clone(),
color: m.color.map(|x| x as u32),
Expand Down
16 changes: 8 additions & 8 deletions src/database/models/notification_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ impl Notification {
let notification_ids_parsed: Vec<i64> = notification_ids.iter().map(|x| x.0).collect();
sqlx::query!(
"
SELECT n.id, n.user_id, n.title, n.text, n.link, n.created, n.read, n.type notification_type, n.body,
JSONB_AGG(DISTINCT jsonb_build_object('id', na.id, 'notification_id', na.notification_id, 'title', na.title, 'action_route_method', na.action_route_method, 'action_route', na.action_route)) filter (where na.id is not null) actions
SELECT n.id, n.user_id, n.name, n.text, n.link, n.created, n.read, n.type notification_type, n.body,
JSONB_AGG(DISTINCT jsonb_build_object('id', na.id, 'notification_id', na.notification_id, 'name', na.name, 'action_route_method', na.action_route_method, 'action_route', na.action_route)) filter (where na.id is not null) actions
FROM notifications n
LEFT OUTER JOIN notifications_actions na on n.id = na.notification_id
WHERE n.id = ANY($1)
Expand All @@ -143,10 +143,10 @@ impl Notification {
read: row.read,
created: row.created,
body: row.body.clone().and_then(|x| serde_json::from_value(x).ok()).unwrap_or_else(|| {
if let Some(title) = row.title {
if let Some(name) = row.name {
NotificationBody::LegacyMarkdown {
notification_type: row.notification_type,
title,
name,
text: row.text.unwrap_or_default(),
link: row.link.unwrap_or_default(),
actions: serde_json::from_value(
Expand Down Expand Up @@ -186,8 +186,8 @@ impl Notification {

let db_notifications = sqlx::query!(
"
SELECT n.id, n.user_id, n.title, n.text, n.link, n.created, n.read, n.type notification_type, n.body,
JSONB_AGG(DISTINCT jsonb_build_object('id', na.id, 'notification_id', na.notification_id, 'title', na.title, 'action_route_method', na.action_route_method, 'action_route', na.action_route)) filter (where na.id is not null) actions
SELECT n.id, n.user_id, n.name, n.text, n.link, n.created, n.read, n.type notification_type, n.body,
JSONB_AGG(DISTINCT jsonb_build_object('id', na.id, 'notification_id', na.notification_id, 'name', na.name, 'action_route_method', na.action_route_method, 'action_route', na.action_route)) filter (where na.id is not null) actions
FROM notifications n
LEFT OUTER JOIN notifications_actions na on n.id = na.notification_id
WHERE n.user_id = $1
Expand All @@ -206,10 +206,10 @@ impl Notification {
read: row.read,
created: row.created,
body: row.body.clone().and_then(|x| serde_json::from_value(x).ok()).unwrap_or_else(|| {
if let Some(title) = row.title {
if let Some(name) = row.name {
NotificationBody::LegacyMarkdown {
notification_type: row.notification_type,
title,
name,
text: row.text.unwrap_or_default(),
link: row.link.unwrap_or_default(),
actions: serde_json::from_value(
Expand Down
12 changes: 6 additions & 6 deletions src/database/models/organization_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Organization {
) -> Result<(), super::DatabaseError> {
sqlx::query!(
"
INSERT INTO organizations (id, title, team_id, description, icon_url, color)
INSERT INTO organizations (id, name, team_id, description, icon_url, color)
VALUES ($1, $2, $3, $4, $5, $6)
",
self.id.0,
Expand Down Expand Up @@ -166,9 +166,9 @@ impl Organization {

let organizations: Vec<Organization> = sqlx::query!(
"
SELECT o.id, o.title, o.team_id, o.description, o.icon_url, o.color
SELECT o.id, o.name, o.team_id, o.description, o.icon_url, o.color
FROM organizations o
WHERE o.id = ANY($1) OR LOWER(o.title) = ANY($2)
WHERE o.id = ANY($1) OR LOWER(o.name) = ANY($2)
GROUP BY o.id;
",
&organization_ids_parsed,
Expand All @@ -181,7 +181,7 @@ impl Organization {
.try_filter_map(|e| async {
Ok(e.right().map(|m| Organization {
id: OrganizationId(m.id),
name: m.title,
name: m.name,
team_id: TeamId(m.team_id),
description: m.description,
icon_url: m.icon_url,
Expand Down Expand Up @@ -226,7 +226,7 @@ impl Organization {
{
let result = sqlx::query!(
"
SELECT o.id, o.title, o.team_id, o.description, o.icon_url, o.color
SELECT o.id, o.name, o.team_id, o.description, o.icon_url, o.color
FROM organizations o
LEFT JOIN mods m ON m.organization_id = o.id
WHERE m.id = $1
Expand All @@ -240,7 +240,7 @@ impl Organization {
if let Some(result) = result {
Ok(Some(Organization {
id: OrganizationId(result.id),
name: result.title,
name: result.name,
team_id: TeamId(result.team_id),
description: result.description,
icon_url: result.icon_url,
Expand Down
27 changes: 12 additions & 15 deletions src/database/models/project_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl GalleryItem {
sqlx::query!(
"
INSERT INTO mods_gallery (
mod_id, image_url, featured, title, description, ordering
mod_id, image_url, featured, name, description, ordering
)
SELECT * FROM UNNEST ($1::bigint[], $2::varchar[], $3::bool[], $4::varchar[], $5::varchar[], $6::bigint[])
",
Expand Down Expand Up @@ -144,8 +144,8 @@ pub struct ProjectBuilder {
pub team_id: TeamId,
pub organization_id: Option<OrganizationId>,
pub name: String,
pub summary: String,
pub description: String,
pub body: String,
pub icon_url: Option<String>,
pub issues_url: Option<String>,
pub source_url: Option<String>,
Expand Down Expand Up @@ -175,9 +175,8 @@ impl ProjectBuilder {
team_id: self.team_id,
organization_id: self.organization_id,
name: self.name,
summary: self.summary,
description: self.description,
body: self.body,
body_url: None,
published: Utc::now(),
updated: Utc::now(),
approved: None,
Expand Down Expand Up @@ -246,9 +245,8 @@ pub struct Project {
pub team_id: TeamId,
pub organization_id: Option<OrganizationId>,
pub name: String,
pub summary: String,
pub description: String,
pub body: String,
pub body_url: Option<String>,
pub published: DateTime<Utc>,
pub updated: DateTime<Utc>,
pub approved: Option<DateTime<Utc>>,
Expand Down Expand Up @@ -281,7 +279,7 @@ impl Project {
sqlx::query!(
"
INSERT INTO mods (
id, team_id, title, description, body,
id, team_id, name, summary, description,
published, downloads, icon_url, issues_url,
source_url, wiki_url, status, requested_status, discord_url,
license_url, license,
Expand All @@ -298,8 +296,8 @@ impl Project {
self.id as ProjectId,
self.team_id as TeamId,
&self.name,
&self.summary,
&self.description,
&self.body,
self.published,
self.downloads,
self.icon_url.as_ref(),
Expand Down Expand Up @@ -567,8 +565,8 @@ impl Project {

let db_projects: Vec<QueryProject> = sqlx::query!(
"
SELECT m.id id, m.title title, m.description description, m.downloads downloads, m.follows follows,
m.icon_url icon_url, m.body body, m.published published,
SELECT m.id id, m.name name, m.summary summary, m.downloads downloads, m.follows follows,
m.icon_url icon_url, m.description description, m.published published,
m.updated updated, m.approved approved, m.queued, m.status status, m.requested_status requested_status,
m.issues_url issues_url, m.source_url source_url, m.wiki_url wiki_url, m.discord_url discord_url, m.license_url license_url,
m.team_id team_id, m.organization_id organization_id, m.license license, m.slug slug, m.moderation_message moderation_message, m.moderation_message_body moderation_message_body,
Expand All @@ -580,7 +578,7 @@ impl Project {
ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is false) categories,
ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is true) additional_categories,
JSONB_AGG(DISTINCT jsonb_build_object('id', v.id, 'date_published', v.date_published)) filter (where v.id is not null) versions,
JSONB_AGG(DISTINCT jsonb_build_object('image_url', mg.image_url, 'featured', mg.featured, 'title', mg.title, 'description', mg.description, 'created', mg.created, 'ordering', mg.ordering)) filter (where mg.image_url is not null) gallery,
JSONB_AGG(DISTINCT jsonb_build_object('image_url', mg.image_url, 'featured', mg.featured, 'name', mg.name, 'description', mg.description, 'created', mg.created, 'ordering', mg.ordering)) filter (where mg.image_url is not null) gallery,
JSONB_AGG(DISTINCT jsonb_build_object('platform_id', md.joining_platform_id, 'platform_short', dp.short, 'platform_name', dp.name,'url', md.url)) filter (where md.joining_platform_id is not null) donations
FROM mods m
INNER JOIN threads t ON t.mod_id = m.id
Expand Down Expand Up @@ -612,10 +610,9 @@ impl Project {
id: ProjectId(id),
team_id: TeamId(m.team_id),
organization_id: m.organization_id.map(OrganizationId),
name: m.title.clone(),
description: m.description.clone(),
name: m.name.clone(),
summary: m.summary.clone(),
downloads: m.downloads,
body_url: None,
icon_url: m.icon_url.clone(),
published: m.published,
updated: m.updated,
Expand All @@ -632,7 +629,7 @@ impl Project {
)),
license: m.license.clone(),
slug: m.slug.clone(),
body: m.body.clone(),
description: m.description.clone(),
follows: m.follows,
moderation_message: m.moderation_message,
moderation_message_body: m.moderation_message_body,
Expand Down
4 changes: 0 additions & 4 deletions src/database/models/version_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ impl VersionBuilder {
name: self.name,
version_number: self.version_number,
changelog: self.changelog,
changelog_url: None,
date_published: Utc::now(),
downloads: 0,
featured: self.featured,
Expand Down Expand Up @@ -293,7 +292,6 @@ pub struct Version {
pub name: String,
pub version_number: String,
pub changelog: String,
pub changelog_url: Option<String>,
pub date_published: DateTime<Utc>,
pub downloads: i32,
pub version_type: String,
Expand Down Expand Up @@ -601,7 +599,6 @@ impl Version {
name: v.version_name,
version_number: v.version_number,
changelog: v.changelog,
changelog_url: None,
date_published: v.date_published,
downloads: v.downloads,
version_type: v.version_type,
Expand Down Expand Up @@ -972,7 +969,6 @@ mod tests {
name: Default::default(),
version_number: Default::default(),
changelog: Default::default(),
changelog_url: Default::default(),
downloads: Default::default(),
version_type: Default::default(),
featured: Default::default(),
Expand Down
10 changes: 5 additions & 5 deletions src/models/v2/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ impl LegacyProject {
id: data.id,
slug: data.slug,
project_type,
team: data.team,
team: data.team_id,
organization: data.organization,
title: data.name,
description: data.description,
body: data.body,
body_url: data.body_url,
description: data.summary, // V2 description is V3 summary
body: data.description, // V2 body is V3 description
body_url: None, // Always None even in V2
published: data.published,
updated: data.updated,
approved: data.approved,
Expand Down Expand Up @@ -293,7 +293,7 @@ impl From<Version> for LegacyVersion {
name: data.name,
version_number: data.version_number,
changelog: data.changelog,
changelog_url: data.changelog_url,
changelog_url: None, // Always None even in V2
date_published: data.date_published,
downloads: data.downloads,
version_type: data.version_type,
Expand Down
6 changes: 3 additions & 3 deletions src/models/v3/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub enum NotificationBody {
},
LegacyMarkdown {
notification_type: Option<String>,
title: String,
name: String, // TODO: Check to make sure this change doesnt break anything
text: String,
link: String,
actions: Vec<NotificationAction>,
Expand Down Expand Up @@ -176,13 +176,13 @@ impl From<DBNotification> for Notification {
),
NotificationBody::LegacyMarkdown {
notification_type,
title,
name,
text,
link,
actions,
} => (
notification_type.clone(),
title.clone(),
name.clone(),
text.clone(),
link.clone(),
actions.clone().into_iter().map(Into::into).collect(),
Expand Down
16 changes: 5 additions & 11 deletions src/models/v3/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@ pub struct Project {
/// The aggregated games of the versions of this project
pub games: Vec<String>,
/// The team of people that has ownership of this project.
pub team: TeamId,
pub team_id: TeamId,
/// The optional organization of people that have ownership of this project.
pub organization: Option<OrganizationId>,
/// The title or name of the project.
pub name: String,
/// A short description of the project.
pub description: String,
pub summary: String,
/// A long form description of the project.
pub body: String,
/// The link to the long description of the project. Deprecated, always None
pub body_url: Option<String>,
pub description: String,

/// The date at which the project was first published.
pub published: DateTime<Utc>,
Expand Down Expand Up @@ -119,12 +117,11 @@ impl From<QueryProject> for Project {
slug: m.slug,
project_types: data.project_types,
games: data.games,
team: m.team_id.into(),
team_id: m.team_id.into(),
organization: m.organization_id.map(|i| i.into()),
name: m.name,
summary: m.summary,
description: m.description,
body: m.body,
body_url: None,
published: m.published,
updated: m.updated,
approved: m.approved,
Expand Down Expand Up @@ -467,8 +464,6 @@ pub struct Version {
pub games: Vec<String>,
/// The changelog for this version of the project.
pub changelog: String,
/// A link to the changelog for this version of the project. Deprecated, always None
pub changelog_url: Option<String>,

/// The date that this version was published.
pub date_published: DateTime<Utc>,
Expand Down Expand Up @@ -520,7 +515,6 @@ impl From<QueryVersion> for Version {
project_types: data.project_types,
games: data.games,
changelog: v.changelog,
changelog_url: None,
date_published: v.date_published,
downloads: v.downloads as u32,
version_type: match v.version_type.as_str() {
Expand Down
4 changes: 2 additions & 2 deletions src/routes/v2/project_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ pub async fn project_create(
Ok(v3::project_creation::ProjectCreateData {
name: legacy_create.title,
slug: legacy_create.slug,
description: legacy_create.description,
body: legacy_create.body,
summary: legacy_create.description, // Description becomes summary
description: legacy_create.body, // Body becomes description
initial_versions,
categories: legacy_create.categories,
additional_categories: legacy_create.additional_categories,
Expand Down
4 changes: 2 additions & 2 deletions src/routes/v2/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ pub async fn project_edit(

let new_project = v3::projects::EditProject {
name: v2_new_project.title,
description: v2_new_project.description,
body: v2_new_project.body,
summary: v2_new_project.description, // Description becomes summary
description: v2_new_project.body, // Body becomes description
categories: v2_new_project.categories,
additional_categories: v2_new_project.additional_categories,
issues_url: v2_new_project.issues_url,
Expand Down
Loading

0 comments on commit 83ab67d

Please sign in to comment.