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

Commit

Permalink
Staging fixes (#766)
Browse files Browse the repository at this point in the history
* fixes bugs

* fixed more things

* fixes version creation

* small change

* removed modpack
  • Loading branch information
thesuzerain authored Nov 24, 2023
1 parent 79e6343 commit ade8c16
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 15 deletions.
45 changes: 45 additions & 0 deletions migrations/20231122111700_adds_missing_loader_field_loaders.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

-- Adds missing fields to loader_fields_loaders
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 = 'game_versions'
AND l.loader = ANY( ARRAY['forge', 'fabric', 'quilt', 'modloader','rift','liteloader', 'neoforge'])
ON CONFLICT (loader_id, loader_field_id) DO NOTHING;

-- Fixes mrpack variants being added to the wrong enum
-- Luckily, mrpack variants are the only ones set to 2 without metadata
UPDATE loader_field_enum_values SET enum_id = 3 WHERE enum_id = 2 AND metadata IS NULL;

-- Because it was mislabeled, version_fields for mrpack_loaders were set to null.
-- 1) Update version_fields corresponding to mrpack_loaders to the correct enum_value
UPDATE version_fields vf
SET enum_value = subquery.lfev_id
FROM (
SELECT vf.version_id, vf.field_id, lfev.id AS lfev_id
FROM version_fields vf
LEFT JOIN versions v ON v.id = vf.version_id
LEFT JOIN loaders_versions lv ON v.id = lv.version_id
LEFT JOIN loaders l ON l.id = lv.loader_id
LEFT JOIN loader_fields lf ON lf.id = vf.field_id
LEFT JOIN loader_field_enum_values lfev ON lfev.value = l.loader AND lf.enum_type = lfev.enum_id
WHERE lf.field = 'mrpack_loaders' AND vf.enum_value IS NULL
) AS subquery
WHERE vf.version_id = subquery.version_id AND vf.field_id = subquery.field_id;

-- 2) Set those versions to mrpack as their version
INSERT INTO loaders_versions (version_id, loader_id)
SELECT DISTINCT vf.version_id, l.id
FROM version_fields vf
LEFT JOIN loader_fields lf ON lf.id = vf.field_id
CROSS JOIN loaders l
WHERE lf.field = 'mrpack_loaders'
AND l.loader = 'mrpack'
ON CONFLICT DO NOTHING;

-- 3) Delete the old versions that had mrpack added to them
DELETE FROM loaders_versions lv
WHERE lv.loader_id != (SELECT id FROM loaders WHERE loader = 'mrpack')
AND lv.version_id IN (
SELECT version_id
FROM loaders_versions
WHERE loader_id = (SELECT id FROM loaders WHERE loader = 'mrpack')
);
10 changes: 3 additions & 7 deletions src/routes/v2/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,10 @@ pub async fn random_projects_get(
let response =
v3::projects::random_projects_get(web::Query(count), pool.clone(), redis.clone()).await?;
// Convert response to V2 format
match v2_reroute::extract_ok_json::<Project>(response).await {
match v2_reroute::extract_ok_json::<Vec<Project>>(response).await {
Ok(project) => {
let version_item = match project.versions.first() {
Some(vid) => version_item::Version::get((*vid).into(), &**pool, &redis).await?,
None => None,
};
let project = LegacyProject::from(project, version_item);
Ok(HttpResponse::Ok().json(project))
let legacy_projects = LegacyProject::from_many(project, &**pool, &redis).await?;
Ok(HttpResponse::Ok().json(legacy_projects))
}
Err(response) => Ok(response),
}
Expand Down
35 changes: 27 additions & 8 deletions src/routes/v2/version_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,33 @@ pub async fn version_create(
fields.insert("client_side".to_string(), json!("required"));
fields.insert("server_side".to_string(), json!("optional"));

// TODO: Some kind of handling here to ensure project type is fine.
// We expect the version uploaded to be of loader type modpack, but there might not be a way to check here for that.
// After all, theoretically, they could be creating a genuine 'fabric' mod, and modpack no longer carries information on whether its a mod or modpack,
// as those are out to the versions.
// Handle project type via file extension prediction
let mut project_type = None;
for file_part in &legacy_create.file_parts {
if let Some(ext) = file_part.split('.').last() {
match ext {
"mrpack" => {
project_type = Some("modpack");
break;
}
// No other type matters
_ => {}
}

Check warning on line 114 in src/routes/v2/version_creation.rs

View workflow job for this annotation

GitHub Actions / clippy

you seem to be trying to use `match` for an equality check. Consider using `if`

warning: you seem to be trying to use `match` for an equality check. Consider using `if` --> src/routes/v2/version_creation.rs:107:21 | 107 | / match ext { 108 | | "mrpack" => { 109 | | project_type = Some("modpack"); 110 | | break; ... | 113 | | _ => {} 114 | | } | |_____________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match = note: `#[warn(clippy::single_match)]` on by default help: try | 107 ~ if ext == "mrpack" { 108 + project_type = Some("modpack"); 109 + break; 110 + } |
break;
}
}

// Ideally this would, if the project 'should' be a modpack:
// - change the loaders to mrpack only
// - add loader fields to the project for the corresponding loaders
// Modpacks now use the "mrpack" loader, and loaders are converted to loader fields.
// Setting of 'project_type' directly is removed, it's loader-based now.
if project_type == Some("modpack") {
fields.insert("mrpack_loaders".to_string(), json!(legacy_create.loaders));
}

let loaders = if project_type == Some("modpack") {
vec![Loader("mrpack".to_string())]
} else {
legacy_create.loaders
};

Ok(v3::version_creation::InitialVersionData {
project_id: legacy_create.project_id,
Expand All @@ -117,7 +136,7 @@ pub async fn version_create(
version_body: legacy_create.version_body,
dependencies: legacy_create.dependencies,
release_channel: legacy_create.release_channel,
loaders: legacy_create.loaders,
loaders,
featured: legacy_create.featured,
primary_file: legacy_create.primary_file,
status: legacy_create.status,
Expand Down

0 comments on commit ade8c16

Please sign in to comment.