add is_public to matches

This commit is contained in:
Ilion Beyst 2022-07-30 17:03:32 +02:00
parent 1d280c62e2
commit ee5c67c092
8 changed files with 17 additions and 2 deletions

View file

@ -0,0 +1 @@
ALTER TABLE matches DROP COLUMN is_public;

View file

@ -0,0 +1 @@
ALTER TABLE matches ADD COLUMN is_public boolean NOT NULL DEFAULT false;

View file

@ -15,6 +15,7 @@ use super::bots::{Bot, BotVersion};
pub struct NewMatch<'a> {
pub state: MatchState,
pub log_path: &'a str,
pub is_public: bool,
}
#[derive(Insertable)]
@ -36,6 +37,7 @@ pub struct MatchBase {
pub log_path: String,
pub created_at: NaiveDateTime,
pub winner: Option<i32>,
pub is_public: bool,
}
#[derive(Queryable, Identifiable, Associations, Clone)]

View file

@ -119,6 +119,7 @@ impl pb::client_api_service_server::ClientApiService for ClientApiServer {
});
let run_match = RunMatch::from_players(
self.runner_config.clone(),
false,
vec![
MatchPlayer::BotSpec {
spec: remote_bot_spec,

View file

@ -17,6 +17,7 @@ pub struct RunMatch {
log_file_name: String,
players: Vec<MatchPlayer>,
config: Arc<GlobalConfig>,
is_public: bool,
}
pub enum MatchPlayer {
@ -30,12 +31,18 @@ pub enum MatchPlayer {
}
impl RunMatch {
pub fn from_players(config: Arc<GlobalConfig>, players: Vec<MatchPlayer>) -> Self {
// TODO: create a MatchParams struct
pub fn from_players(
config: Arc<GlobalConfig>,
is_public: bool,
players: Vec<MatchPlayer>,
) -> Self {
let log_file_name = format!("{}.log", gen_alphanumeric(16));
RunMatch {
config,
log_file_name,
players,
is_public,
}
}
@ -80,6 +87,7 @@ impl RunMatch {
let new_match_data = db::matches::NewMatch {
state: db::matches::MatchState::Playing,
log_path: &self.log_file_name,
is_public: self.is_public,
};
let new_match_players = self
.players

View file

@ -53,7 +53,7 @@ async fn play_ranking_match(
players.push(player);
}
let (_, handle) = RunMatch::from_players(config, players)
let (_, handle) = RunMatch::from_players(config, true, players)
.run(db_pool.clone())
.await
.expect("failed to run match");

View file

@ -50,6 +50,7 @@ pub async fn submit_bot(
let run_match = RunMatch::from_players(
config,
false,
vec![
MatchPlayer::BotVersion {
bot: None,

View file

@ -47,6 +47,7 @@ table! {
log_path -> Text,
created_at -> Timestamp,
winner -> Nullable<Int4>,
is_public -> Bool,
}
}