aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src/db
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-07-05 20:34:20 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-07-05 20:34:20 +0200
commitb3df5c6f8cc59e099a2f1db3df8089af4abca02e (patch)
tree8b717834ab72165610b1548bb080a3299d936936 /planetwars-server/src/db
parent8a47b948eb88f1e0ff649880a70f9416306bac92 (diff)
downloadplanetwars.dev-b3df5c6f8cc59e099a2f1db3df8089af4abca02e.tar.xz
planetwars.dev-b3df5c6f8cc59e099a2f1db3df8089af4abca02e.zip
migrate code_bundles to bot_versions
Diffstat (limited to 'planetwars-server/src/db')
-rw-r--r--planetwars-server/src/db/bots.rs21
-rw-r--r--planetwars-server/src/db/matches.rs14
2 files changed, 18 insertions, 17 deletions
diff --git a/planetwars-server/src/db/bots.rs b/planetwars-server/src/db/bots.rs
index 108c692..964deaa 100644
--- a/planetwars-server/src/db/bots.rs
+++ b/planetwars-server/src/db/bots.rs
@@ -1,7 +1,7 @@
use diesel::prelude::*;
use serde::{Deserialize, Serialize};
-use crate::schema::{bots, code_bundles};
+use crate::schema::{bot_versions, bots};
use chrono;
#[derive(Insertable)]
@@ -44,38 +44,39 @@ pub fn find_all_bots(conn: &PgConnection) -> QueryResult<Vec<Bot>> {
}
#[derive(Insertable)]
-#[table_name = "code_bundles"]
+#[table_name = "bot_versions"]
pub struct NewCodeBundle<'a> {
pub bot_id: Option<i32>,
- pub path: &'a str,
+ pub code_bundle_path: &'a str,
}
#[derive(Queryable, Serialize, Deserialize, Debug)]
pub struct CodeBundle {
pub id: i32,
pub bot_id: Option<i32>,
- pub path: String,
+ pub code_bundle_path: Option<String>,
pub created_at: chrono::NaiveDateTime,
+ pub container_digest: Option<String>,
}
pub fn create_code_bundle(
new_code_bundle: &NewCodeBundle,
conn: &PgConnection,
) -> QueryResult<CodeBundle> {
- diesel::insert_into(code_bundles::table)
+ diesel::insert_into(bot_versions::table)
.values(new_code_bundle)
.get_result(conn)
}
pub fn find_bot_code_bundles(bot_id: i32, conn: &PgConnection) -> QueryResult<Vec<CodeBundle>> {
- code_bundles::table
- .filter(code_bundles::bot_id.eq(bot_id))
+ bot_versions::table
+ .filter(bot_versions::bot_id.eq(bot_id))
.get_results(conn)
}
pub fn active_code_bundle(bot_id: i32, conn: &PgConnection) -> QueryResult<CodeBundle> {
- code_bundles::table
- .filter(code_bundles::bot_id.eq(bot_id))
- .order(code_bundles::created_at.desc())
+ bot_versions::table
+ .filter(bot_versions::bot_id.eq(bot_id))
+ .order(bot_versions::created_at.desc())
.first(conn)
}
diff --git a/planetwars-server/src/db/matches.rs b/planetwars-server/src/db/matches.rs
index 54fd113..d9d893c 100644
--- a/planetwars-server/src/db/matches.rs
+++ b/planetwars-server/src/db/matches.rs
@@ -6,7 +6,7 @@ use diesel::{
};
use diesel::{Connection, GroupedBy, PgConnection, QueryResult};
-use crate::schema::{bots, code_bundles, match_players, matches};
+use crate::schema::{bot_versions, bots, match_players, matches};
use super::bots::{Bot, CodeBundle};
@@ -93,10 +93,10 @@ pub fn list_matches(conn: &PgConnection) -> QueryResult<Vec<FullMatchData>> {
let match_players = MatchPlayer::belonging_to(&matches)
.left_join(
- code_bundles::table
- .on(match_players::code_bundle_id.eq(code_bundles::id.nullable())),
+ bot_versions::table
+ .on(match_players::code_bundle_id.eq(bot_versions::id.nullable())),
)
- .left_join(bots::table.on(code_bundles::bot_id.eq(bots::id.nullable())))
+ .left_join(bots::table.on(bot_versions::bot_id.eq(bots::id.nullable())))
.load::<FullMatchPlayerData>(conn)?
.grouped_by(&matches);
@@ -146,10 +146,10 @@ pub fn find_match(id: i32, conn: &PgConnection) -> QueryResult<FullMatchData> {
let match_players = MatchPlayer::belonging_to(&match_base)
.left_join(
- code_bundles::table
- .on(match_players::code_bundle_id.eq(code_bundles::id.nullable())),
+ bot_versions::table
+ .on(match_players::code_bundle_id.eq(bot_versions::id.nullable())),
)
- .left_join(bots::table.on(code_bundles::bot_id.eq(bots::id.nullable())))
+ .left_join(bots::table.on(bot_versions::bot_id.eq(bots::id.nullable())))
.load::<FullMatchPlayerData>(conn)?;
let res = FullMatchData {