-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
268 additions
and
30 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
File renamed without changes.
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
File renamed without changes.
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,48 @@ | ||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.6 | ||
use std::collections::HashSet; | ||
|
||
use sea_orm::entity::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
use spherical_go_game_lib::{PointID, StoredGameMove, StoredGameMoveType}; | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] | ||
#[sea_orm(table_name = "history_records")] | ||
pub struct Model { | ||
#[sea_orm(primary_key, auto_increment = false)] | ||
pub id: Uuid, | ||
pub history_id: Uuid, | ||
pub point_id: i32, | ||
pub died_points_ids: Vec<i32>, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation { | ||
#[sea_orm( | ||
belongs_to = "super::histories::Entity", | ||
from = "Column::HistoryId", | ||
to = "super::histories::Column::Id", | ||
on_update = "NoAction", | ||
on_delete = "Cascade" | ||
)] | ||
Histories, | ||
} | ||
|
||
impl Related<super::histories::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Histories.def() | ||
} | ||
} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} | ||
|
||
impl Into<StoredGameMove> for Model { | ||
fn into(self) -> StoredGameMove { | ||
// TODO: update logic once you add other move types to the db table | ||
StoredGameMove { | ||
move_type: StoredGameMoveType::Move, | ||
point_id: Some(self.point_id as PointID), | ||
died: HashSet::from_iter(self.died_points_ids.into_iter().map(|p| p as PointID)), | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
server/src/common/db/entity/src/lib.rs → server/libs/entity/src/lib.rs
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod games; | ||
pub mod histories; | ||
pub mod history_records; | ||
pub mod rooms; | ||
pub mod users; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
60 changes: 60 additions & 0 deletions
60
server/libs/migration/src/m20230108_204629_history_records.rs
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,60 @@ | ||
use sea_orm_migration::prelude::*; | ||
|
||
use crate::m20230106_155413_histories::History; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.create_table( | ||
Table::create() | ||
.table(HistoryRecord::Table) | ||
.if_not_exists() | ||
.col( | ||
ColumnDef::new(HistoryRecord::Id) | ||
.uuid() | ||
.not_null() | ||
.primary_key(), | ||
) | ||
.col(ColumnDef::new(HistoryRecord::HistoryID).uuid().not_null()) | ||
.foreign_key( | ||
ForeignKey::create() | ||
.name("fk-history_record-history-id") | ||
.on_delete(ForeignKeyAction::Cascade) | ||
.from_col(HistoryRecord::HistoryID) | ||
.to(History::Table, History::Id), | ||
) | ||
.col(ColumnDef::new(HistoryRecord::PointID).integer().not_null()) | ||
.col( | ||
ColumnDef::new(HistoryRecord::DiedPointsIds) | ||
.array(ColumnType::Integer(None)) | ||
.not_null(), | ||
) | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.drop_table(Table::drop().table(HistoryRecord::Table).to_owned()) | ||
.await | ||
} | ||
} | ||
|
||
/// Learn more at https://docs.rs/sea-query#iden | ||
#[derive(Iden)] | ||
#[iden = "history_records"] | ||
enum HistoryRecord { | ||
Table, | ||
Id, | ||
#[iden = "history_id"] | ||
HistoryID, | ||
#[iden = "point_id"] | ||
PointID, | ||
#[iden = "died_points_ids"] | ||
DiedPointsIds, | ||
} |
File renamed without changes.
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
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
Oops, something went wrong.