Staging fixes (#766)
* fixes bugs * fixed more things * fixes version creation * small change * removed modpack
This commit is contained in:
parent
79e634316d
commit
ade8c162cd
@ -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')
|
||||
);
|
||||
@ -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),
|
||||
}
|
||||
|
||||
@ -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
|
||||
_ => {}
|
||||
}
|
||||
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,
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user