Add dump_games command
So the frontend can map game db ids to nexus names.
This commit is contained in:
parent
7d229ccd1a
commit
782f7a473f
@ -13,6 +13,7 @@ if [ -n "$last_update_time" ]; then
|
||||
./target/release/mod-mapper -c cells &>> logs/modmapper.log
|
||||
./target/release/mod-mapper -s mods/mod_search_index.json &>> logs/modmapper.log
|
||||
./target/release/mod-mapper -M mods/mod_cell_counts.json &>> logs/modmapper.log
|
||||
./target/release/mod-mapper -G mods/games.json &>> logs/modmapper.log
|
||||
./target/release/mod-mapper -m mods -u "$last_update_time" &>> logs/modmapper.log
|
||||
./target/release/mod-mapper -P plugins_data -u "$last_update_time" &>> logs/modmapper.log
|
||||
./target/release/mod-mapper -F files -u "$last_update_time" &>> logs/modmapper.log
|
||||
@ -21,6 +22,7 @@ else
|
||||
./target/release/mod-mapper -c cells &>> logs/modmapper.log
|
||||
./target/release/mod-mapper -s mods/mod_search_index.json &>> logs/modmapper.log
|
||||
./target/release/mod-mapper -M mods/mod_cell_counts.json &>> logs/modmapper.log
|
||||
./target/release/mod-mapper -G mods/games.json &>> logs/modmapper.log
|
||||
./target/release/mod-mapper -m mods &>> logs/modmapper.log
|
||||
./target/release/mod-mapper -P plugins_data &>> logs/modmapper.log
|
||||
./target/release/mod-mapper -F files &>> logs/modmapper.log
|
||||
|
14
src/commands/dump_games.rs
Normal file
14
src/commands/dump_games.rs
Normal file
@ -0,0 +1,14 @@
|
||||
use anyhow::Result;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use tracing::info;
|
||||
|
||||
use crate::models::game;
|
||||
|
||||
pub async fn dump_games(pool: &sqlx::Pool<sqlx::Postgres>, path: &str) -> Result<()> {
|
||||
let games = game::get_all(&pool).await?;
|
||||
info!("writing {} games to {}", games.len(), path);
|
||||
let mut file = File::create(path)?;
|
||||
write!(file, "{}", serde_json::to_string(&games)?)?;
|
||||
return Ok(());
|
||||
}
|
@ -7,6 +7,7 @@ pub mod dump_mod_data;
|
||||
pub mod dump_mod_search_index;
|
||||
pub mod dump_plugin_data;
|
||||
pub mod dump_file_data;
|
||||
pub mod dump_games;
|
||||
pub mod update;
|
||||
|
||||
pub use download_tiles::download_tiles;
|
||||
@ -17,4 +18,5 @@ pub use dump_mod_data::dump_mod_data;
|
||||
pub use dump_mod_search_index::dump_mod_search_index;
|
||||
pub use dump_plugin_data::dump_plugin_data;
|
||||
pub use dump_file_data::dump_file_data;
|
||||
pub use dump_games::dump_games;
|
||||
pub use update::update;
|
||||
|
@ -14,7 +14,7 @@ mod plugin_processor;
|
||||
|
||||
use commands::{
|
||||
backfills::backfill_is_translation, download_tiles, dump_cell_data, dump_cell_edit_counts,
|
||||
dump_mod_cell_counts, dump_mod_data, dump_mod_search_index, dump_plugin_data, dump_file_data, update,
|
||||
dump_mod_cell_counts, dump_mod_data, dump_mod_search_index, dump_plugin_data, dump_file_data, dump_games, update,
|
||||
};
|
||||
|
||||
#[derive(FromArgs)]
|
||||
@ -60,6 +60,10 @@ struct Args {
|
||||
#[argh(option, short = 'F')]
|
||||
file_data: Option<String>,
|
||||
|
||||
/// file to output all the game data as json
|
||||
#[argh(option, short = 'G')]
|
||||
game_data: Option<String>,
|
||||
|
||||
/// folder to output all map tile images downloaded from the UESP wiki
|
||||
#[argh(option, short = 't')]
|
||||
download_tiles: Option<String>,
|
||||
@ -107,6 +111,9 @@ pub async fn main() -> Result<()> {
|
||||
if let Some(path) = args.file_data {
|
||||
return dump_file_data(&pool, &path, args.updated_after).await;
|
||||
}
|
||||
if let Some(path) = args.game_data {
|
||||
return dump_games(&pool, &path).await;
|
||||
}
|
||||
if let Some(dir) = args.download_tiles {
|
||||
return download_tiles(&dir).await;
|
||||
}
|
||||
|
@ -32,3 +32,16 @@ pub async fn insert(
|
||||
.await
|
||||
.context("Failed to insert game")
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(pool))]
|
||||
pub async fn get_all(
|
||||
pool: &sqlx::Pool<sqlx::Postgres>,
|
||||
) -> Result<Vec<Game>> {
|
||||
sqlx::query_as!(
|
||||
Game,
|
||||
"SELECT * FROM games"
|
||||
)
|
||||
.fetch_all(pool)
|
||||
.await
|
||||
.context("Failed to fetch games")
|
||||
}
|
@ -48,6 +48,7 @@ pub struct UnsavedMod<'a> {
|
||||
pub struct ModForSearch {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub game_id: i32,
|
||||
pub nexus_mod_id: i32,
|
||||
}
|
||||
|
||||
@ -359,6 +360,7 @@ pub async fn batched_get_for_search(
|
||||
"SELECT
|
||||
id,
|
||||
name,
|
||||
game_id,
|
||||
nexus_mod_id
|
||||
FROM mods
|
||||
WHERE id > $2
|
||||
|
Loading…
Reference in New Issue
Block a user