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

Plugins #758

Merged
merged 5 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

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

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');
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
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
3 changes: 3 additions & 0 deletions tests/files/dummy_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ INSERT INTO loaders_project_types (joining_loader_id, joining_project_type_id) V
INSERT INTO loaders (id, loader) VALUES (6, 'forge');
INSERT INTO loaders_project_types (joining_loader_id, joining_project_type_id) VALUES (6,1);

INSERT INTO loaders (id, loader, metadata) VALUES (7, 'bukkit', '{"platform":false}'::jsonb);
INSERT INTO loaders (id, loader, metadata) VALUES (8, 'waterfall', '{"platform":true}'::jsonb);

-- Adds dummies to mrpack_loaders
INSERT INTO loader_field_enum_values (enum_id, value) SELECT id, 'fabric' FROM loader_field_enums WHERE enum_name = 'mrpack_loaders';
INSERT INTO loader_field_enum_values (enum_id, value) SELECT id, 'forge' FROM loader_field_enums WHERE enum_name = 'mrpack_loaders';
Expand Down
13 changes: 10 additions & 3 deletions tests/tags.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use common::environment::TestEnvironment;
use std::collections::HashSet;
use std::collections::{HashMap, HashSet};

mod common;

Expand All @@ -11,14 +11,21 @@ async fn get_tags() {
let loaders = api.get_loaders_deserialized().await;
let categories = api.get_categories_deserialized().await;

let loader_names = loaders.into_iter().map(|x| x.name).collect::<HashSet<_>>();
let loader_metadata = loaders
.into_iter()
.map(|x| (x.name, x.metadata.get("platform").and_then(|x| x.as_bool())))
.collect::<HashMap<_, _>>();
let loader_names = loader_metadata.keys().cloned().collect::<HashSet<String>>();
assert_eq!(
loader_names,
["fabric", "forge", "mrpack"]
["fabric", "forge", "mrpack", "bukkit", "waterfall"]
.iter()
.map(|s| s.to_string())
.collect()
);
assert_eq!(loader_metadata["fabric"], None);
assert_eq!(loader_metadata["bukkit"], Some(false));
assert_eq!(loader_metadata["waterfall"], Some(true));

let category_names = categories
.into_iter()
Expand Down
28 changes: 18 additions & 10 deletions tests/v2/tags.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use itertools::Itertools;

use crate::common::environment::TestEnvironment;
use std::collections::HashSet;

Expand All @@ -11,31 +13,37 @@ async fn get_tags() {
let side_types = api.get_side_types_deserialized().await;
let categories = api.get_categories_deserialized().await;

// These tests match dummy data and will need to be updated if the dummy data changes;
// These tests match dummy data and will need to be updated if the dummy data changes
// Versions should be ordered by:
// - ordering
// - ordering ties settled by date added to database
// - We also expect presentation of NEWEST to OLDEST
// - All null orderings are treated as older than any non-null ordering
// (for this test, the 1.20.1, etc, versions are all null ordering)
let game_version_versions = game_versions
.into_iter()
.map(|x| x.version)
.collect::<HashSet<_>>();
.collect::<Vec<_>>();
assert_eq!(
game_version_versions,
[
"1.20.1",
"1.20.2",
"1.20.3",
"1.20.4",
"1.20.5",
"Ordering_Negative1",
"Ordering_Positive100"
"Ordering_Positive100",
"1.20.5",
"1.20.4",
"1.20.3",
"1.20.2",
"1.20.1"
]
.iter()
.map(|s| s.to_string())
.collect()
.collect_vec()
);

let loader_names = loaders.into_iter().map(|x| x.name).collect::<HashSet<_>>();
assert_eq!(
loader_names,
["fabric", "forge", "mrpack"]
["fabric", "forge", "mrpack", "bukkit", "waterfall"]
.iter()
.map(|s| s.to_string())
.collect()
Expand Down
Loading