feat(labrinth): rework v3 side types to a single environment field (#3701)

* feat(labrinth): rework v3 side types to a single `environment` field

This field is meant to be able to represent the existing v2 side type
information and beyond, in a way that may also be slightly easier to
comprehend.

* chore(labrinth/migrations): use proper val for `HAVING` clause

* feat(labrinth): add `side_types_migration_review_status` field to projects
This commit is contained in:
Alejandro González
2025-06-17 00:44:57 +02:00
committed by GitHub
parent 65126b3a23
commit ef04dcc37b
22 changed files with 358 additions and 205 deletions

View File

@@ -73,10 +73,7 @@ pub fn get_public_version_creation_data_json(
// Loader fields
"game_versions": ["1.20.1"],
"singleplayer": true,
"client_and_server": true,
"client_only": true,
"server_only": false,
"environment": "client_only_server_optional",
});
if is_modpack {
j["mrpack_loaders"] = json!(["fabric"]);

View File

@@ -63,7 +63,7 @@ pub async fn setup_search_projects(
let id = 0;
let modify_json = serde_json::from_value(json!([
{ "op": "add", "path": "/categories", "value": DUMMY_CATEGORIES[4..6] },
{ "op": "add", "path": "/initial_versions/0/server_only", "value": true },
{ "op": "add", "path": "/initial_versions/0/environment", "value": "server_only" },
{ "op": "add", "path": "/license_id", "value": "LGPL-3.0-or-later" },
]))
.unwrap();
@@ -78,7 +78,7 @@ pub async fn setup_search_projects(
let id = 1;
let modify_json = serde_json::from_value(json!([
{ "op": "add", "path": "/categories", "value": DUMMY_CATEGORIES[0..2] },
{ "op": "add", "path": "/initial_versions/0/client_only", "value": false },
{ "op": "add", "path": "/initial_versions/0/environment", "value": "client_or_server" },
]))
.unwrap();
project_creation_futures.push(create_async_future(
@@ -92,7 +92,7 @@ pub async fn setup_search_projects(
let id = 2;
let modify_json = serde_json::from_value(json!([
{ "op": "add", "path": "/categories", "value": DUMMY_CATEGORIES[0..2] },
{ "op": "add", "path": "/initial_versions/0/server_only", "value": true },
{ "op": "add", "path": "/initial_versions/0/environment", "value": "server_only" },
{ "op": "add", "path": "/name", "value": "Mysterious Project" },
]))
.unwrap();
@@ -107,7 +107,7 @@ pub async fn setup_search_projects(
let id = 3;
let modify_json = serde_json::from_value(json!([
{ "op": "add", "path": "/categories", "value": DUMMY_CATEGORIES[0..3] },
{ "op": "add", "path": "/initial_versions/0/server_only", "value": true },
{ "op": "add", "path": "/initial_versions/0/environment", "value": "server_only" },
{ "op": "add", "path": "/initial_versions/0/game_versions", "value": ["1.20.4"] },
{ "op": "add", "path": "/name", "value": "Mysterious Project" },
{ "op": "add", "path": "/license_id", "value": "LicenseRef-All-Rights-Reserved" },
@@ -124,7 +124,7 @@ pub async fn setup_search_projects(
let id = 4;
let modify_json = serde_json::from_value(json!([
{ "op": "add", "path": "/categories", "value": DUMMY_CATEGORIES[0..3] },
{ "op": "add", "path": "/initial_versions/0/client_only", "value": false },
{ "op": "add", "path": "/initial_versions/0/environment", "value": "client_or_server" },
{ "op": "add", "path": "/initial_versions/0/game_versions", "value": ["1.20.5"] },
]))
.unwrap();
@@ -139,7 +139,7 @@ pub async fn setup_search_projects(
let id = 5;
let modify_json = serde_json::from_value(json!([
{ "op": "add", "path": "/categories", "value": DUMMY_CATEGORIES[5..6] },
{ "op": "add", "path": "/initial_versions/0/client_only", "value": false },
{ "op": "add", "path": "/initial_versions/0/environment", "value": "client_or_server" },
{ "op": "add", "path": "/initial_versions/0/game_versions", "value": ["1.20.5"] },
{ "op": "add", "path": "/license_id", "value": "LGPL-3.0-or-later" },
]))
@@ -155,8 +155,7 @@ pub async fn setup_search_projects(
let id = 6;
let modify_json = serde_json::from_value(json!([
{ "op": "add", "path": "/categories", "value": DUMMY_CATEGORIES[5..6] },
{ "op": "add", "path": "/initial_versions/0/client_only", "value": false },
{ "op": "add", "path": "/initial_versions/0/server_only", "value": true },
{ "op": "add", "path": "/initial_versions/0/environment", "value": "client_or_server_prefers_both" },
{ "op": "add", "path": "/license_id", "value": "LGPL-3.0-or-later" },
]))
.unwrap();
@@ -173,8 +172,7 @@ pub async fn setup_search_projects(
let id = 7;
let modify_json = serde_json::from_value(json!([
{ "op": "add", "path": "/categories", "value": DUMMY_CATEGORIES[5..6] },
{ "op": "add", "path": "/initial_versions/0/client_only", "value": false },
{ "op": "add", "path": "/initial_versions/0/server_only", "value": true },
{ "op": "add", "path": "/initial_versions/0/environment", "value": "client_or_server_prefers_both" },
{ "op": "add", "path": "/license_id", "value": "LGPL-3.0-or-later" },
{ "op": "add", "path": "/initial_versions/0/loaders", "value": ["forge"] },
{ "op": "add", "path": "/initial_versions/0/game_versions", "value": ["1.20.2"] },

View File

@@ -67,8 +67,8 @@ VALUES (2, 'Ordering_Negative1', '{"type":"release","major":false}', -1);
INSERT INTO loader_field_enum_values(enum_id, value, metadata, ordering)
VALUES (2, 'Ordering_Positive100', '{"type":"release","major":false}', 100);
INSERT INTO loader_fields_loaders(loader_id, loader_field_id)
SELECT l.id, lf.id FROM loaders l CROSS JOIN loader_fields lf WHERE lf.field IN ('game_versions','singleplayer', 'client_and_server', 'client_only', 'server_only') ON CONFLICT DO NOTHING;
INSERT INTO loader_fields_loaders(loader_id, loader_field_id)
SELECT l.id, lf.id FROM loaders l CROSS JOIN loader_fields lf WHERE lf.field IN ('game_versions','environment') ON CONFLICT DO NOTHING;
INSERT INTO categories (id, category, project_type) VALUES
(51, 'combat', 1),
@@ -108,6 +108,6 @@ VALUES (
INSERT INTO oauth_client_redirect_uris (id, client_id, uri) VALUES (1, 1, 'https://modrinth.com/oauth_callback');
-- Create dummy data table to mark that this file has been run
CREATE TABLE dummy_data (
CREATE TABLE dummy_data (
update_id bigint PRIMARY KEY
);

View File

@@ -114,7 +114,7 @@ async fn creating_loader_fields() {
Some(
serde_json::from_value(json!([{
"op": "remove",
"path": "/singleplayer"
"path": "/environment"
}]))
.unwrap(),
),
@@ -273,12 +273,8 @@ async fn creating_loader_fields() {
"value": ["1.20.1", "1.20.2"]
}, {
"op": "add",
"path": "/singleplayer",
"value": false
}, {
"op": "add",
"path": "/server_only",
"value": true
"path": "/environment",
"value": "client_or_server_prefers_both"
}]))
.unwrap(),
),
@@ -286,16 +282,17 @@ async fn creating_loader_fields() {
)
.await;
assert_eq!(&v.fields["game_versions"], &json!(["1.20.1", "1.20.2"]));
assert_eq!(&v.fields["singleplayer"], &json!(false));
assert_eq!(&v.fields["server_only"], &json!(true));
assert_eq!(
&v.fields["environment"],
&json!("client_or_server_prefers_both")
);
// - Patch
let resp = api
.edit_version(
alpha_version_id,
json!({
"game_versions": ["1.20.1", "1.20.2"],
"singleplayer": false,
"server_only": true
"environment": "client_or_server_prefers_both"
}),
USER_USER_PAT,
)
@@ -320,8 +317,8 @@ async fn creating_loader_fields() {
"value": ["1.20.5"]
}, {
"op": "add",
"path": "/singleplayer",
"value": false
"path": "/environment",
"value": "client_or_server"
}]))
.unwrap(),
),
@@ -357,8 +354,13 @@ async fn creating_loader_fields() {
&project.fields["game_versions"],
&[json!("1.20.1"), json!("1.20.2"), json!("1.20.5")]
);
assert!(project.fields["singleplayer"].contains(&json!(false)));
assert!(project.fields["singleplayer"].contains(&json!(true)));
assert!(
project.fields["environment"].contains(&json!("client_or_server"))
);
assert!(
project.fields["environment"]
.contains(&json!("client_or_server_prefers_both"))
);
})
.await
}
@@ -421,10 +423,7 @@ async fn get_available_loader_fields() {
fabric_loader_fields,
[
"game_versions",
"singleplayer",
"client_and_server",
"client_only",
"server_only",
"environment",
"test_fabric_optional" // exists for testing
]
.iter()
@@ -444,10 +443,7 @@ async fn get_available_loader_fields() {
mrpack_loader_fields,
[
"game_versions",
"singleplayer",
"client_and_server",
"client_only",
"server_only",
"environment",
// mrpack has all the general fields as well as this
"mrpack_loaders"
]

View File

@@ -52,8 +52,11 @@ async fn search_projects() {
vec![1, 2, 3, 4],
),
(json!([["project_types:modpack"]]), vec![4]),
(json!([["client_only:true"]]), vec![0, 2, 3, 7, 9]),
(json!([["server_only:true"]]), vec![0, 2, 3, 6, 7]),
(json!([["environment:server_only"]]), vec![0, 2, 3]),
(
json!([["environment:client_or_server_prefers_both"]]),
vec![6, 7],
),
(json!([["open_source:true"]]), vec![0, 1, 2, 4, 5, 6, 7, 9]),
(json!([["license:MIT"]]), vec![1, 2, 4, 9]),
(json!([[r#"name:'Mysterious Project'"#]]), vec![2, 3]),