Skip to content

Commit 45eb02f

Browse files
committed
New project component metadata schema
1 parent a98174b commit 45eb02f

11 files changed

+321
-276
lines changed

apps/labrinth/.sqlx/query-46f309eb085e487bf868d4fee5170eef9d1af5ff41b097b3552de86d3940e01e.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/labrinth/.sqlx/query-7a6d6a91e6bd27f7be34b8cc7955a66c4175ebd1c55e437f187f61efca681c62.json renamed to apps/labrinth/.sqlx/query-59b6eea93ce248d2b1eaf14fe8970bba8ccd2df0995a21bdb34ae3214cef6377.json

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/labrinth/.sqlx/query-ee74bbff42dd29ab5a23d5811ea18e62ac199fe5e68275bf1bc7c71ace630702.json renamed to apps/labrinth/.sqlx/query-cf0ce4ce54edc7533332f0bfab27d977a9613f8aa22669c0f8fe7bab2d5d6192.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/labrinth/.sqlx/query-ef91f2b725b5a81f56d9031bf95da4588d37cf9f0da26cdd23cfe025b191a2d4.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,2 @@
1-
CREATE TABLE minecraft_server_projects (
2-
id bigint PRIMARY KEY NOT NULL
3-
REFERENCES mods(id)
4-
ON DELETE CASCADE,
5-
max_players int NOT NULL
6-
);
7-
8-
CREATE TABLE minecraft_java_server_projects (
9-
id bigint PRIMARY KEY NOT NULL
10-
REFERENCES mods(id)
11-
ON DELETE CASCADE,
12-
address varchar(255) NOT NULL
13-
);
14-
15-
CREATE TABLE minecraft_bedrock_server_projects (
16-
id bigint PRIMARY KEY NOT NULL
17-
REFERENCES mods(id)
18-
ON DELETE CASCADE,
19-
address varchar(255) NOT NULL
20-
);
1+
ALTER TABLE mods
2+
ADD COLUMN components JSONB NOT NULL DEFAULT '{}';

apps/labrinth/src/database/models/project_item.rs

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use super::{DBUser, ids::*};
66
use crate::database::models::DatabaseError;
77
use crate::database::redis::RedisPool;
88
use crate::database::{PgTransaction, models};
9+
use crate::models::exp;
910
use crate::models::projects::{
1011
MonetizationStatus, ProjectStatus, SideTypesMigrationReviewStatus,
1112
};
@@ -176,6 +177,7 @@ pub struct ProjectBuilder {
176177
pub gallery_items: Vec<DBGalleryItem>,
177178
pub color: Option<u32>,
178179
pub monetization_status: MonetizationStatus,
180+
pub components: exp::ProjectSerial,
179181
}
180182

181183
impl ProjectBuilder {
@@ -215,6 +217,7 @@ impl ProjectBuilder {
215217
side_types_migration_review_status:
216218
SideTypesMigrationReviewStatus::Reviewed,
217219
loaders: vec![],
220+
components: self.components,
218221
};
219222
project_struct.insert(&mut *transaction).await?;
220223

@@ -294,6 +297,7 @@ pub struct DBProject {
294297
pub monetization_status: MonetizationStatus,
295298
pub side_types_migration_review_status: SideTypesMigrationReviewStatus,
296299
pub loaders: Vec<String>,
300+
pub components: exp::ProjectSerial,
297301
}
298302

299303
impl DBProject {
@@ -308,14 +312,16 @@ impl DBProject {
308312
published, downloads, icon_url, raw_icon_url, status, requested_status,
309313
license_url, license,
310314
slug, color, monetization_status, organization_id,
311-
side_types_migration_review_status
315+
side_types_migration_review_status,
316+
components
312317
)
313318
VALUES (
314319
$1, $2, $3, $4, $5, $6,
315320
$7, $8, $9, $10, $11,
316321
$12, $13,
317322
LOWER($14), $15, $16, $17,
318-
$18
323+
$18,
324+
$19
319325
)
320326
",
321327
self.id as DBProjectId,
@@ -335,7 +341,8 @@ impl DBProject {
335341
self.color.map(|x| x as i32),
336342
self.monetization_status.as_str(),
337343
self.organization_id.map(|x| x.0 as i64),
338-
self.side_types_migration_review_status.as_str()
344+
self.side_types_migration_review_status.as_str(),
345+
serde_json::to_value(&self.components).expect("serialization shouldn't fail"),
339346
)
340347
.execute(&mut *transaction)
341348
.await?;
@@ -778,24 +785,13 @@ impl DBProject {
778785
m.side_types_migration_review_status side_types_migration_review_status,
779786
ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is false) categories,
780787
ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is true) additional_categories,
781-
-- components
782-
COUNT(c1.id) > 0 AS minecraft_server_exists,
783-
MAX(c1.max_players) AS minecraft_server_max_players,
784-
COUNT(c2.id) > 0 AS minecraft_java_server_exists,
785-
MAX(c2.address) AS minecraft_java_server_address,
786-
COUNT(c3.id) > 0 AS minecraft_bedrock_server_exists,
787-
MAX(c3.address) AS minecraft_bedrock_server_address
788+
m.components AS "components: sqlx::types::Json<exp::ProjectSerial>"
788789
789790
FROM mods m
790791
INNER JOIN threads t ON t.mod_id = m.id
791792
LEFT JOIN mods_categories mc ON mc.joining_mod_id = m.id
792793
LEFT JOIN categories c ON mc.joining_category_id = c.id
793794
794-
-- components
795-
LEFT JOIN minecraft_server_projects c1 ON c1.id = m.id
796-
LEFT JOIN minecraft_java_server_projects c2 ON c2.id = m.id
797-
LEFT JOIN minecraft_bedrock_server_projects c3 ON c3.id = m.id
798-
799795
WHERE m.id = ANY($1) OR m.slug = ANY($2)
800796
GROUP BY t.id, m.id
801797
"#,
@@ -859,6 +855,7 @@ impl DBProject {
859855
&m.side_types_migration_review_status,
860856
),
861857
loaders,
858+
components: exp::ProjectSerial::default(),
862859
},
863860
categories: m.categories.unwrap_or_default(),
864861
additional_categories: m.additional_categories.unwrap_or_default(),
@@ -872,21 +869,21 @@ impl DBProject {
872869
urls,
873870
aggregate_version_fields: VersionField::from_query_json(version_fields, &loader_fields, &loader_field_enum_values, true),
874871
thread_id: DBThreadId(m.thread_id),
875-
minecraft_server: if m.minecraft_server_exists.unwrap_or(false) {
876-
Some(exp::minecraft::Server {
877-
max_players: m.minecraft_server_max_players.unwrap().cast_unsigned(),
878-
})
879-
} else { None },
880-
minecraft_java_server: if m.minecraft_java_server_exists.unwrap_or(false) {
881-
Some(exp::minecraft::JavaServer {
882-
address: m.minecraft_java_server_address.unwrap(),
883-
})
884-
} else { None },
885-
minecraft_bedrock_server: if m.minecraft_bedrock_server_exists.unwrap_or(false) {
886-
Some(exp::minecraft::BedrockServer {
887-
address: m.minecraft_bedrock_server_address.unwrap(),
888-
})
889-
} else { None },
872+
minecraft_server: m
873+
.components
874+
.0
875+
.minecraft_server
876+
.map(exp::ProjectComponent::from_serial),
877+
minecraft_java_server: m
878+
.components
879+
.0
880+
.minecraft_java_server
881+
.map(exp::ProjectComponent::from_serial),
882+
minecraft_bedrock_server: m
883+
.components
884+
.0
885+
.minecraft_bedrock_server
886+
.map(exp::ProjectComponent::from_serial),
890887
};
891888

892889
acc.insert(m.id, (m.slug, project));

0 commit comments

Comments
 (0)