create maps table

This commit is contained in:
Ilion Beyst 2022-08-23 20:00:21 +02:00
parent fa4c684475
commit aa066ef5bb
5 changed files with 28 additions and 13 deletions

View file

@ -0,0 +1,3 @@
ALTER TABLE matches DROP COLUMN map_id;
DROP TABLE maps;

View file

@ -0,0 +1,7 @@
CREATE TABLE maps (
id SERIAL PRIMARY KEY,
name TEXT UNIQUE NOT NULL,
file_path TEXT NOT NULL
);
ALTER TABLE matches ADD COLUMN map_id INTEGER REFERENCES maps(id);

View file

@ -41,6 +41,7 @@ pub struct MatchBase {
pub created_at: NaiveDateTime, pub created_at: NaiveDateTime,
pub winner: Option<i32>, pub winner: Option<i32>,
pub is_public: bool, pub is_public: bool,
pub map_id: Option<i32>,
} }
#[derive(Queryable, Identifiable, Associations, Clone)] #[derive(Queryable, Identifiable, Associations, Clone)]
@ -166,14 +167,7 @@ pub fn list_bot_matches(
bot_versions::table.on(match_players::bot_version_id.eq(bot_versions::id.nullable())), bot_versions::table.on(match_players::bot_version_id.eq(bot_versions::id.nullable())),
) )
.filter(bot_versions::bot_id.eq(bot_id)) .filter(bot_versions::bot_id.eq(bot_id))
.select(( .select(matches::all_columns)
matches::id,
matches::state,
matches::log_path,
matches::created_at,
matches::winner,
matches::is_public,
))
.into_boxed(); .into_boxed();
let matches = let matches =

View file

@ -79,11 +79,8 @@ pub async fn list_recent_matches(
matches.truncate(requested_count); matches.truncate(requested_count);
} }
let api_matches = matches let api_matches = matches.into_iter().map(match_data_to_api).collect();
.into_iter()
.map(match_data_to_api)
.collect();
Ok(Json(ListMatchesResponse { Ok(Json(ListMatchesResponse {
matches: api_matches, matches: api_matches,
has_next, has_next,

View file

@ -26,6 +26,17 @@ table! {
} }
} }
table! {
use diesel::sql_types::*;
use crate::db_types::*;
maps (id) {
id -> Int4,
name -> Text,
file_path -> Text,
}
}
table! { table! {
use diesel::sql_types::*; use diesel::sql_types::*;
use crate::db_types::*; use crate::db_types::*;
@ -48,6 +59,7 @@ table! {
created_at -> Timestamp, created_at -> Timestamp,
winner -> Nullable<Int4>, winner -> Nullable<Int4>,
is_public -> Bool, is_public -> Bool,
map_id -> Nullable<Int4>,
} }
} }
@ -87,12 +99,14 @@ table! {
joinable!(bots -> users (owner_id)); joinable!(bots -> users (owner_id));
joinable!(match_players -> bot_versions (bot_version_id)); joinable!(match_players -> bot_versions (bot_version_id));
joinable!(match_players -> matches (match_id)); joinable!(match_players -> matches (match_id));
joinable!(matches -> maps (map_id));
joinable!(ratings -> bots (bot_id)); joinable!(ratings -> bots (bot_id));
joinable!(sessions -> users (user_id)); joinable!(sessions -> users (user_id));
allow_tables_to_appear_in_same_query!( allow_tables_to_appear_in_same_query!(
bot_versions, bot_versions,
bots, bots,
maps,
match_players, match_players,
matches, matches,
ratings, ratings,