aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src/modules/bots.rs
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-07-23 23:40:25 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-07-23 23:40:25 +0200
commit4a582e8079178a7ac11f2a492e7988fcdaa210cd (patch)
tree1403b3e409e184bb53e0349d7e68e673fe7d7b3c /planetwars-server/src/modules/bots.rs
parentf19a70e710b8bf4605625516aa7e4c0cc7ace2e4 (diff)
downloadplanetwars.dev-4a582e8079178a7ac11f2a492e7988fcdaa210cd.tar.xz
planetwars.dev-4a582e8079178a7ac11f2a492e7988fcdaa210cd.zip
store active version id in bots table
Diffstat (limited to 'planetwars-server/src/modules/bots.rs')
-rw-r--r--planetwars-server/src/modules/bots.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/planetwars-server/src/modules/bots.rs b/planetwars-server/src/modules/bots.rs
index 5513539..4aba168 100644
--- a/planetwars-server/src/modules/bots.rs
+++ b/planetwars-server/src/modules/bots.rs
@@ -5,6 +5,7 @@ use diesel::{PgConnection, QueryResult};
use crate::{db, util::gen_alphanumeric, GlobalConfig};
/// Save a string containing bot code as a code bundle.
+/// If a bot was provided, set the saved bundle as its active version.
pub fn save_code_string(
bot_code: &str,
bot_id: Option<i32>,
@@ -22,5 +23,11 @@ pub fn save_code_string(
code_bundle_path: Some(&bundle_name),
container_digest: None,
};
- db::bots::create_bot_version(&new_code_bundle, conn)
+ let version = db::bots::create_bot_version(&new_code_bundle, conn)?;
+ // Leave this coupled for now - this is how the behaviour was bevore.
+ // It would be cleaner to separate version setting and bot selection, though.
+ if let Some(bot_id) = bot_id {
+ db::bots::set_active_version(bot_id, Some(version.id), conn)?;
+ }
+ Ok(version)
}