-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bin): script for increasing artifacts of users (#83)
* feat(bin): script increasing artifacts * fix: change bonus artifact count * fix: add log after threads --------- Co-authored-by: DonWIck32 <[email protected]>
- Loading branch information
1 parent
a8baf59
commit c49b4f2
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use anyhow::Ok; | ||
use aot_backend::constants::BANK_BUILDING_NAME; | ||
use aot_backend::models::BlockCategory; | ||
use aot_backend::schema::{artifact, block_type, building_type, map_spaces, user}; | ||
use aot_backend::util; | ||
use diesel::prelude::*; | ||
use diesel::QueryDsl; | ||
|
||
fn main() { | ||
let artifacts_to_increase_for_all_players = 750; | ||
|
||
let pool = util::get_pg_conn_pool(); | ||
let mut conn = pool.get().expect("Could not retrieve connection from pool"); | ||
|
||
// list of all bank's (level 1, 2, 3) space ids | ||
let map_space_ids: Vec<i32> = map_spaces::table | ||
.inner_join(block_type::table.inner_join(building_type::table)) | ||
.filter(block_type::category.eq(BlockCategory::Building)) | ||
.filter(building_type::name.like(BANK_BUILDING_NAME)) | ||
.select(map_spaces::id) | ||
.load::<i32>(&mut conn) | ||
.expect("Could not get map space ids"); | ||
|
||
let _ = Ok(conn.transaction(|conn| { | ||
for map_space_id in map_space_ids { | ||
diesel::update(artifact::table.filter(artifact::map_space_id.eq(map_space_id))) | ||
.set(artifact::count.eq(artifact::count + artifacts_to_increase_for_all_players)) | ||
.execute(conn)?; | ||
} | ||
|
||
diesel::update(user::table) | ||
.set(user::artifacts.eq(user::artifacts + artifacts_to_increase_for_all_players)) | ||
.execute(conn)?; | ||
|
||
Ok(()) | ||
})); | ||
|
||
println!( | ||
"Added {} artifacts to all users", | ||
artifacts_to_increase_for_all_players | ||
); | ||
} |