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 27, 2023
2 parents 3741654 + fd18185 commit 46092c5
Show file tree
Hide file tree
Showing 24 changed files with 552 additions and 84 deletions.

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

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

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

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

7 changes: 7 additions & 0 deletions migrations/20231122230639_oauth_client_metadata.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Add migration script here
ALTER TABLE
oauth_clients
ADD
COLUMN url text NULL,
ADD
COLUMN description text NULL;
31 changes: 31 additions & 0 deletions migrations/20231125080100_drops_mods_dp_plugins.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- For every loader that has a loaders_project_types entry that connects it to the project_types 'plugin',
-- remove all non plugin project_types entries for that loader.
-- This is to ensure that the plugin project_types is the only one that is used for the plugin loaders

--plugin
DELETE FROM loaders_project_types
WHERE joining_loader_id IN (
SELECT DISTINCT l.id
FROM loaders l
LEFT JOIN loaders_project_types lpt ON lpt.joining_loader_id = l.id
LEFT JOIN project_types pt ON pt.id = lpt.joining_project_type_id
WHERE pt.name = 'plugin'
)
AND joining_project_type_id NOT IN (
SELECT id FROM project_types
WHERE name = 'plugin'
);

--datapack
DELETE FROM loaders_project_types
WHERE joining_loader_id IN (
SELECT DISTINCT l.id
FROM loaders l
LEFT JOIN loaders_project_types lpt ON lpt.joining_loader_id = l.id
LEFT JOIN project_types pt ON pt.id = lpt.joining_project_type_id
WHERE pt.name = 'datapack'
)
AND joining_project_type_id NOT IN (
SELECT id FROM project_types
WHERE name = 'datapack'
);
52 changes: 51 additions & 1 deletion src/database/models/loader_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const GAMES_LIST_NAMESPACE: &str = "games";
const LOADER_ID: &str = "loader_id";
const LOADERS_LIST_NAMESPACE: &str = "loaders";
const LOADER_FIELDS_NAMESPACE: &str = "loader_fields";
const LOADER_FIELDS_NAMESPACE_ALL: &str = "loader_fields_all";
const LOADER_FIELD_ENUMS_ID_NAMESPACE: &str = "loader_field_enums";
const LOADER_FIELD_ENUM_VALUES_NAMESPACE: &str = "loader_field_enum_values";

Expand Down Expand Up @@ -396,8 +397,57 @@ impl LoaderField {
.collect();
Ok(result)
}
}

// Gets all fields for a given loader(s)
// This is for tags, which need all fields for all loaders
// We want to return them even in testing situations where we dont have loaders or loader_fields_loaders set up
pub async fn get_fields_all<'a, E>(
exec: E,
redis: &RedisPool,
) -> Result<Vec<LoaderField>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
let mut redis = redis.connect().await?;

let cached_fields: Option<Vec<LoaderField>> = redis
.get(LOADER_FIELDS_NAMESPACE_ALL, "")
.await?
.and_then(|x| serde_json::from_str::<Vec<LoaderField>>(&x).ok());

if let Some(cached_fields) = cached_fields {
return Ok(cached_fields);
}

let result = sqlx::query!(
"
SELECT DISTINCT lf.id, lf.field, lf.field_type, lf.optional, lf.min_val, lf.max_val, lf.enum_type
FROM loader_fields lf
",
)
.fetch_many(exec)
.try_filter_map(|e| async {
Ok(e.right().and_then(|r| {
Some(LoaderField {
id: LoaderFieldId(r.id),
field_type: LoaderFieldType::build(&r.field_type, r.enum_type)?,
field: r.field,
optional: r.optional,
min_val: r.min_val,
max_val: r.max_val,
})
}))
})
.try_collect::<Vec<LoaderField>>()
.await?;

redis
.set_serialized_to_json(LOADER_FIELDS_NAMESPACE_ALL, "", &result, None)
.await?;

Ok(result)
}
}
impl LoaderFieldEnum {
pub async fn get<'a, E>(
enum_name: &str, // Note: NOT loader field name
Expand Down
14 changes: 12 additions & 2 deletions src/database/models/oauth_client_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub struct OAuthClient {
pub redirect_uris: Vec<OAuthRedirectUri>,
pub created: DateTime<Utc>,
pub created_by: UserId,
pub url: Option<String>,
pub description: Option<String>,
}

struct ClientQueryResult {
Expand All @@ -33,6 +35,8 @@ struct ClientQueryResult {
secret_hash: String,
created: DateTime<Utc>,
created_by: i64,
url: Option<String>,
description: Option<String>,
uri_ids: Option<Vec<i64>>,
uri_vals: Option<Vec<String>>,
}
Expand All @@ -53,6 +57,8 @@ macro_rules! select_clients_with_predicate {
clients.secret_hash as "secret_hash!",
clients.created as "created!",
clients.created_by as "created_by!",
clients.url as "url?",
clients.description as "description?",
uris.uri_ids as "uri_ids?",
uris.uri_vals as "uri_vals?"
FROM oauth_clients clients
Expand Down Expand Up @@ -155,12 +161,14 @@ impl OAuthClient {
sqlx::query!(
"
UPDATE oauth_clients
SET name = $1, icon_url = $2, max_scopes = $3
WHERE (id = $4)
SET name = $1, icon_url = $2, max_scopes = $3, url = $4, description = $5
WHERE (id = $6)
",
self.name,
self.icon_url,
self.max_scopes.to_postgres(),
self.url,
self.description,
self.id.0,
)
.execute(exec)
Expand Down Expand Up @@ -240,6 +248,8 @@ impl From<ClientQueryResult> for OAuthClient {
redirect_uris: redirects,
created: r.created,
created_by: UserId(r.created_by),
url: r.url,
description: r.description,
}
}
}
1 change: 1 addition & 0 deletions src/models/v2/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// Legacy models from V2, where its useful to keep the struct for rerouting/conversion
pub mod projects;
pub mod search;
6 changes: 5 additions & 1 deletion src/models/v2/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ impl LegacyProject {

// V2 versions only have one project type- v3 versions can rarely have multiple.
// We'll just use the first one.
let mut project_type = data.project_types.first().cloned().unwrap_or_default();
let mut project_type = data
.project_types
.first()
.cloned()
.unwrap_or("unknown".to_string());
let mut loaders = data.loaders;

if let Some(versions_item) = versions_item {
Expand Down
Loading

0 comments on commit 46092c5

Please sign in to comment.