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

Commit

Permalink
Merge branch 'master' into payouts-code
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometrically authored Nov 26, 2023
2 parents 84e4209 + bad350e commit 3741654
Show file tree
Hide file tree
Showing 58 changed files with 7,795 additions and 6,716 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ rust_iso3166 = "0.1.11"

[dev-dependencies]
actix-http = "3.4.0"

json-patch = "*"
[profile.dev]
opt-level = 0 # Minimal optimization, speeds up compilation
lto = false # Disables Link Time Optimization
Expand Down
46 changes: 46 additions & 0 deletions migrations/20231115105022_plugins_datapacks_v3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
ALTER TABLE loaders ADD COLUMN metadata jsonb NOT NULL DEFAULT '{}'::jsonb;

-- Set 'platform' to 'true' for all plugin loaders
-- From knossos v2
-- pluginLoaders: ['bukkit', 'spigot', 'paper', 'purpur', 'sponge', 'folia'],
-- pluginPlatformLoaders: ['bungeecord', 'waterfall', 'velocity'],
-- allPluginLoaders: [
-- 'bukkit',
-- 'spigot',
-- 'paper',
-- 'purpur',
-- 'sponge',
-- 'bungeecord',
-- 'waterfall',
-- 'velocity',
-- 'folia',
-- ],
-- dataPackLoaders: ['datapack'],
-- modLoaders: ['forge', 'fabric', 'quilt', 'liteloader', 'modloader', 'rift', 'neoforge'],
UPDATE loaders SET metadata = jsonb_set(metadata, '{platform}', 'false'::jsonb) WHERE loader in ('bukkit', 'spigot', 'paper', 'purpur', 'sponge', 'folia');
UPDATE loaders SET metadata = jsonb_set(metadata, '{platform}', 'true'::jsonb) WHERE loader in ('bungeecord', 'waterfall', 'velocity');

INSERT INTO project_types (name) VALUES ('plugin');
INSERT INTO project_types (name) VALUES ('datapack');

INSERT INTO loaders_project_types (joining_loader_id, joining_project_type_id)
SELECT l.id, pt.id
FROM loaders l
CROSS JOIN project_types pt
WHERE l.loader in ('datapack')
AND pt.name = 'datapack';

INSERT INTO loaders_project_types (joining_loader_id, joining_project_type_id)
SELECT l.id, pt.id
FROM loaders l
CROSS JOIN project_types pt
WHERE l.loader in ('bukkit', 'spigot', 'paper', 'purpur', 'sponge', 'bungeecord', 'waterfall', 'velocity', 'folia')
AND pt.name = 'plugin';

INSERT INTO loaders_project_types_games (loader_id, project_type_id, game_id)
SELECT joining_loader_id, joining_project_type_id, g.id
FROM loaders_project_types lpt
INNER JOIN project_types pt ON pt.id = lpt.joining_project_type_id
CROSS JOIN games g
WHERE g.name = 'minecraft'
AND pt.name in ('plugin', 'datapack');
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')
);
7 changes: 5 additions & 2 deletions src/database/models/loader_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub struct Loader {
pub icon: String,
pub supported_project_types: Vec<String>,
pub supported_games: Vec<String>, // slugs
pub metadata: serde_json::Value,
}

impl Loader {
Expand Down Expand Up @@ -136,7 +137,7 @@ impl Loader {

let result = sqlx::query!(
"
SELECT l.id id, l.loader loader, l.icon icon,
SELECT l.id id, l.loader loader, l.icon icon, l.metadata metadata,
ARRAY_AGG(DISTINCT pt.name) filter (where pt.name is not null) project_types,
ARRAY_AGG(DISTINCT g.slug) filter (where g.slug is not null) games
FROM loaders l
Expand All @@ -161,7 +162,9 @@ impl Loader {
.collect(),
supported_games: x
.games
.unwrap_or_default()
.unwrap_or_default(),
metadata: x.metadata

}))
})
.try_collect::<Vec<_>>()
Expand Down
6 changes: 4 additions & 2 deletions src/models/v2/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,12 @@ pub struct LegacyVersion {
/// and are now part of the dynamic fields system
/// A list of game versions this project supports
pub game_versions: Vec<String>,
/// A list of loaders this project supports

/// A list of loaders this project supports (has a newtype struct)
pub loaders: Vec<Loader>,

// TODO: remove this once we have v3 testing, as this is a v3 field and tests for it should be isolated to v3
// TODO: should we remove this? as this is a v3 field and tests for it should be isolated to v3
// it allows us to keep tests that use this struct in common
pub ordering: Option<i32>,

pub id: VersionId,
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" | "mrpack-primary" => {
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,
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
1 change: 0 additions & 1 deletion src/routes/v3/project_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,6 @@ async fn create_initial_version(
&mut loader_field_enum_values,
)?;

println!("Made it past here");
let dependencies = version_data
.dependencies
.iter()
Expand Down
2 changes: 2 additions & 0 deletions src/routes/v3/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub struct LoaderData {
pub name: String,
pub supported_project_types: Vec<String>,
pub supported_games: Vec<String>,
pub metadata: Value,
}

pub async fn loader_list(
Expand All @@ -98,6 +99,7 @@ pub async fn loader_list(
name: x.loader,
supported_project_types: x.supported_project_types,
supported_games: x.supported_games,
metadata: x.metadata,
})
.collect::<Vec<_>>();

Expand Down
Loading

0 comments on commit 3741654

Please sign in to comment.