Skip to content

Commit d7b7649

Browse files
database redesign
1 parent 39aaee2 commit d7b7649

File tree

17 files changed

+965
-456
lines changed

17 files changed

+965
-456
lines changed

docker-compose.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: '3.8'
21

32
services:
43
rusty_backend:
@@ -20,8 +19,6 @@ services:
2019
- backend_net
2120
command: ["./rusty_backend"] # Command to start the application
2221
env_file: .env.example
23-
# ADD AWS CREDS to run code runner
24-
2522
postgres:
2623
image: postgres:latest
2724
container_name: postgres
@@ -44,7 +41,7 @@ services:
4441
- backend_net
4542
volumes:
4643
- ./:/app # Mount project directory to /app in the container
47-
env_file: .env.example
44+
env_file: .env
4845

4946
docker:
5047
image: docker:dind
@@ -74,5 +71,4 @@ networks:
7471
volumes:
7572
postgres_data:
7673
rusty_backend-docker-certs:
77-
rusty_backend-data:
78-
rusty_backend-data:
74+
rusty_backend-data:

entity/src/avatar.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0-rc.5
22
33
use sea_orm::entity::prelude::*;
4-
use serde::{Deserialize, Serialize};
54

6-
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
5+
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
76
#[sea_orm(table_name = "avatar")]
87
pub struct Model {
98
#[sea_orm(primary_key)]
109
pub id: i32,
11-
pub user_name: String,
10+
pub user_id: i32,
1211
pub object_key: String,
1312
}
1413

1514
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
1615
pub enum Relation {
1716
#[sea_orm(
1817
belongs_to = "super::users::Entity",
19-
from = "Column::UserName",
20-
to = "super::users::Column::UserName",
21-
on_update = "Cascade",
18+
from = "Column::UserId",
19+
to = "super::users::Column::Id",
20+
on_update = "NoAction",
2221
on_delete = "Cascade"
2322
)]
2423
Users,

entity/src/game_sessions.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0-rc.5
2+
3+
use sea_orm::entity::prelude::*;
4+
5+
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
6+
#[sea_orm(table_name = "game_sessions")]
7+
pub struct Model {
8+
#[sea_orm(primary_key)]
9+
pub id: i32,
10+
pub male_id: i32,
11+
pub female_id: i32,
12+
#[sea_orm(column_type = "Float")]
13+
pub score: f32,
14+
pub game_id: i32,
15+
pub match_id: i32,
16+
}
17+
18+
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
19+
pub enum Relation {
20+
#[sea_orm(
21+
belongs_to = "super::matches::Entity",
22+
from = "Column::MatchId",
23+
to = "super::matches::Column::Id",
24+
on_update = "NoAction",
25+
on_delete = "Cascade"
26+
)]
27+
Matches,
28+
#[sea_orm(
29+
belongs_to = "super::users::Entity",
30+
from = "Column::FemaleId",
31+
to = "super::users::Column::Id",
32+
on_update = "NoAction",
33+
on_delete = "Cascade"
34+
)]
35+
Users2,
36+
#[sea_orm(
37+
belongs_to = "super::users::Entity",
38+
from = "Column::MaleId",
39+
to = "super::users::Column::Id",
40+
on_update = "NoAction",
41+
on_delete = "Cascade"
42+
)]
43+
Users1,
44+
}
45+
46+
impl Related<super::matches::Entity> for Entity {
47+
fn to() -> RelationDef {
48+
Relation::Matches.def()
49+
}
50+
}
51+
52+
impl ActiveModelBehavior for ActiveModel {}

entity/src/matches.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0-rc.5
2+
3+
use sea_orm::entity::prelude::*;
4+
use serde::Serialize;
5+
6+
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize)]
7+
#[sea_orm(table_name = "matches")]
8+
pub struct Model {
9+
#[sea_orm(primary_key)]
10+
pub id: i32,
11+
pub male_id: i32,
12+
pub female_id: i32,
13+
pub status: String,
14+
}
15+
16+
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
17+
pub enum Relation {
18+
#[sea_orm(has_many = "super::game_sessions::Entity")]
19+
GameSessions,
20+
#[sea_orm(
21+
belongs_to = "super::users::Entity",
22+
from = "Column::FemaleId",
23+
to = "super::users::Column::Id",
24+
on_update = "NoAction",
25+
on_delete = "Cascade"
26+
)]
27+
Users2,
28+
#[sea_orm(
29+
belongs_to = "super::users::Entity",
30+
from = "Column::MaleId",
31+
to = "super::users::Column::Id",
32+
on_update = "NoAction",
33+
on_delete = "Cascade"
34+
)]
35+
Users1,
36+
}
37+
38+
impl Related<super::game_sessions::Entity> for Entity {
39+
fn to() -> RelationDef {
40+
Relation::GameSessions.def()
41+
}
42+
}
43+
44+
impl ActiveModelBehavior for ActiveModel {}

entity/src/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
pub mod prelude;
44

55
pub mod avatar;
6-
pub mod friend_list;
7-
pub mod matched;
6+
pub mod game_sessions;
7+
pub mod matches;
88
pub mod pass_reset;
9+
pub mod user_details;
910
pub mod users;

entity/src/pass_reset.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ pub struct Model {
1313
}
1414

1515
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
16-
pub enum Relation {}
16+
pub enum Relation {
17+
#[sea_orm(
18+
belongs_to = "super::users::Entity",
19+
from = "Column::UserId",
20+
to = "super::users::Column::Id",
21+
on_update = "NoAction",
22+
on_delete = "Cascade"
23+
)]
24+
Users,
25+
}
26+
27+
impl Related<super::users::Entity> for Entity {
28+
fn to() -> RelationDef {
29+
Relation::Users.def()
30+
}
31+
}
1732

1833
impl ActiveModelBehavior for ActiveModel {}

entity/src/prelude.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0-rc.5
22
33
pub use super::avatar::Entity as Avatar;
4-
pub use super::friend_list::Entity as FriendList;
5-
pub use super::matched::Entity as Matched;
4+
pub use super::game_sessions::Entity as GameSessions;
5+
pub use super::matches::Entity as Matches;
66
pub use super::pass_reset::Entity as PassReset;
7+
pub use super::user_details::Entity as UserDetails;
78
pub use super::users::Entity as Users;

entity/src/user_details.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0-rc.5
2+
3+
use sea_orm::entity::prelude::*;
4+
use serde::Serialize;
5+
6+
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize)]
7+
#[sea_orm(table_name = "user_details")]
8+
pub struct Model {
9+
#[sea_orm(primary_key, auto_increment = false)]
10+
pub user_id: i32,
11+
pub location: String,
12+
pub openness: String,
13+
pub interests: String,
14+
pub exp_qual: String,
15+
pub relation_type: String,
16+
pub social_habits: String,
17+
pub past_relations: String,
18+
pub values: String,
19+
pub style: String,
20+
pub traits: String,
21+
pub commitment: String,
22+
pub resolution: String,
23+
pub image_url: String,
24+
#[sea_orm(column_type = "Float")]
25+
pub score: f32,
26+
}
27+
28+
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
29+
pub enum Relation {
30+
#[sea_orm(
31+
belongs_to = "super::users::Entity",
32+
from = "Column::UserId",
33+
to = "super::users::Column::Id",
34+
on_update = "NoAction",
35+
on_delete = "Cascade"
36+
)]
37+
Users,
38+
}
39+
40+
impl Related<super::users::Entity> for Entity {
41+
fn to() -> RelationDef {
42+
Relation::Users.def()
43+
}
44+
}
45+
46+
impl ActiveModelBehavior for ActiveModel {}

entity/src/users.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,33 @@
11
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0-rc.5
22
33
use sea_orm::entity::prelude::*;
4-
use serde::{Deserialize, Serialize};
4+
use serde::Serialize;
55

6-
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
6+
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize)]
77
#[sea_orm(table_name = "users")]
88
pub struct Model {
99
#[sea_orm(primary_key)]
1010
pub id: i32,
1111
#[sea_orm(unique)]
12-
pub user_name: String,
13-
pub first_name: Option<String>,
14-
pub last_name: Option<String>,
12+
pub username: String,
13+
pub first_name: String,
14+
pub last_name: String,
15+
pub age: i32,
1516
#[sea_orm(unique)]
1617
pub email: String,
1718
pub password: String,
18-
pub age: i32,
1919
pub gender: String,
20-
pub location: Option<String>,
21-
pub openness: Option<String>,
22-
pub interests: Option<String>,
23-
pub exp_qual: Option<String>,
24-
pub relation_type: Option<String>,
25-
pub social_habits: Option<String>,
26-
pub past_relations: Option<String>,
27-
pub values: Option<String>,
28-
pub style: Option<String>,
29-
pub traits: Option<String>,
30-
pub commitment: Option<String>,
31-
pub resolution: Option<String>,
32-
pub image_url: String,
33-
pub score: i32,
34-
#[sea_orm(unique)]
35-
pub uuid: Uuid,
3620
pub created_at: DateTime,
3721
}
3822

3923
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
4024
pub enum Relation {
4125
#[sea_orm(has_many = "super::avatar::Entity")]
4226
Avatar,
27+
#[sea_orm(has_many = "super::pass_reset::Entity")]
28+
PassReset,
29+
#[sea_orm(has_many = "super::user_details::Entity")]
30+
UserDetails,
4331
}
4432

4533
impl Related<super::avatar::Entity> for Entity {
@@ -48,4 +36,16 @@ impl Related<super::avatar::Entity> for Entity {
4836
}
4937
}
5038

39+
impl Related<super::pass_reset::Entity> for Entity {
40+
fn to() -> RelationDef {
41+
Relation::PassReset.def()
42+
}
43+
}
44+
45+
impl Related<super::user_details::Entity> for Entity {
46+
fn to() -> RelationDef {
47+
Relation::UserDetails.def()
48+
}
49+
}
50+
5151
impl ActiveModelBehavior for ActiveModel {}

migration/src/lib.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,13 @@ mod m20240929_173839_pass_reset_table;
88
mod m20240930_194047_pass_reset_table2;
99
mod m20241004_152931_pass_reset3;
1010
mod m20241103_131410_avatar_table;
11+
mod m20250322_102921_redesign;
1112

1213
pub struct Migrator;
1314

1415
#[async_trait::async_trait]
1516
impl MigratorTrait for Migrator {
1617
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
17-
vec![
18-
Box::new(m20220101_000001_create_table::Migration),
19-
Box::new(m20240822_161852_create_friendlist::Migration),
20-
Box::new(m20240822_171309_add_field_to_friendlist::Migration),
21-
Box::new(m20240823_075457_create_matched::Migration),
22-
Box::new(m20240929_173839_pass_reset_table::Migration),
23-
Box::new(m20240930_194047_pass_reset_table2::Migration),
24-
Box::new(m20241004_152931_pass_reset3::Migration),
25-
Box::new(m20241103_131410_avatar_table::Migration),
26-
]
18+
vec![Box::new(m20250322_102921_redesign::Migration)]
2719
}
2820
}

0 commit comments

Comments
 (0)