Skip to content

Commit

Permalink
Added last_message_uuid to get all chats
Browse files Browse the repository at this point in the history
  • Loading branch information
myOmikron committed May 20, 2023
1 parent 3b0e54c commit ca1ad42
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 105 deletions.
161 changes: 83 additions & 78 deletions migrations/0001_initial.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Migration]
Hash = "1007693435009946095"
Hash = "1464912175188051413"
Initial = true
Replaces = []

Expand Down Expand Up @@ -57,28 +57,7 @@ Annotations = []

[[Migration.Operations]]
Type = "CreateModel"
Name = "invite"

[[Migration.Operations.Fields]]
Name = "uuid"
Type = "varbinary"

[[Migration.Operations.Fields.Annotations]]
Type = "primary_key"

[[Migration.Operations.Fields]]
Name = "created_at"
Type = "datetime"

[[Migration.Operations.Fields.Annotations]]
Type = "auto_create_time"

[[Migration.Operations.Fields.Annotations]]
Type = "not_null"

[[Migration.Operations]]
Type = "CreateModel"
Name = "friend"
Name = "chatroom"

[[Migration.Operations.Fields]]
Name = "uuid"
Expand All @@ -88,22 +67,9 @@ Type = "varbinary"
Type = "primary_key"

[[Migration.Operations.Fields]]
Name = "is_request"
Type = "boolean"

[[Migration.Operations.Fields.Annotations]]
Type = "not_null"

[[Migration.Operations]]
Type = "CreateModel"
Name = "chatroom"

[[Migration.Operations.Fields]]
Name = "uuid"
Name = "last_message_uuid"
Type = "varbinary"

[[Migration.Operations.Fields.Annotations]]
Type = "primary_key"
Annotations = []

[[Migration.Operations]]
Type = "CreateModel"
Expand Down Expand Up @@ -158,6 +124,24 @@ Type = "auto_create_time"
[[Migration.Operations.Fields.Annotations]]
Type = "not_null"

[[Migration.Operations]]
Type = "CreateModel"
Name = "friend"

[[Migration.Operations.Fields]]
Name = "uuid"
Type = "varbinary"

[[Migration.Operations.Fields.Annotations]]
Type = "primary_key"

[[Migration.Operations.Fields]]
Name = "is_request"
Type = "boolean"

[[Migration.Operations.Fields.Annotations]]
Type = "not_null"

[[Migration.Operations]]
Type = "CreateModel"
Name = "game"
Expand Down Expand Up @@ -222,6 +206,27 @@ Type = "varbinary"
[[Migration.Operations.Fields.Annotations]]
Type = "primary_key"

[[Migration.Operations]]
Type = "CreateModel"
Name = "invite"

[[Migration.Operations.Fields]]
Name = "uuid"
Type = "varbinary"

[[Migration.Operations.Fields.Annotations]]
Type = "primary_key"

[[Migration.Operations.Fields]]
Name = "created_at"
Type = "datetime"

[[Migration.Operations.Fields.Annotations]]
Type = "auto_create_time"

[[Migration.Operations.Fields.Annotations]]
Type = "not_null"

[[Migration.Operations]]
Type = "CreateModel"
Name = "lobby"
Expand Down Expand Up @@ -352,17 +357,17 @@ Type = "not_null"

[[Migration.Operations]]
Type = "CreateField"
Model = "gameaccount"
Model = "friend"

[Migration.Operations.Field]
Name = "game"
Name = "from"
Type = "varbinary"

[[Migration.Operations.Field.Annotations]]
Type = "foreign_key"

[Migration.Operations.Field.Annotations.Value]
TableName = "game"
TableName = "account"
ColumnName = "uuid"
OnDelete = "Cascade"
OnUpdate = "Cascade"
Expand All @@ -372,10 +377,10 @@ Type = "not_null"

[[Migration.Operations]]
Type = "CreateField"
Model = "gameaccount"
Model = "friend"

[Migration.Operations.Field]
Name = "player"
Name = "to"
Type = "varbinary"

[[Migration.Operations.Field.Annotations]]
Expand All @@ -392,27 +397,24 @@ Type = "not_null"

[[Migration.Operations]]
Type = "CreateField"
Model = "lobby"
Model = "friend"

[Migration.Operations.Field]
Name = "owner"
Name = "chat_room"
Type = "varbinary"

[[Migration.Operations.Field.Annotations]]
Type = "foreign_key"

[Migration.Operations.Field.Annotations.Value]
TableName = "account"
TableName = "chatroom"
ColumnName = "uuid"
OnDelete = "Cascade"
OnUpdate = "Cascade"

[[Migration.Operations.Field.Annotations]]
Type = "not_null"

[[Migration.Operations]]
Type = "CreateField"
Model = "lobby"
Model = "chatroommember"

[Migration.Operations.Field]
Name = "chat_room"
Expand All @@ -432,10 +434,10 @@ Type = "not_null"

[[Migration.Operations]]
Type = "CreateField"
Model = "invite"
Model = "chatroommember"

[Migration.Operations.Field]
Name = "from"
Name = "member"
Type = "varbinary"

[[Migration.Operations.Field.Annotations]]
Expand All @@ -452,10 +454,10 @@ Type = "not_null"

[[Migration.Operations]]
Type = "CreateField"
Model = "invite"
Model = "lobby"

[Migration.Operations.Field]
Name = "to"
Name = "owner"
Type = "varbinary"

[[Migration.Operations.Field.Annotations]]
Expand All @@ -472,17 +474,17 @@ Type = "not_null"

[[Migration.Operations]]
Type = "CreateField"
Model = "invite"
Model = "lobby"

[Migration.Operations.Field]
Name = "lobby"
Name = "chat_room"
Type = "varbinary"

[[Migration.Operations.Field.Annotations]]
Type = "foreign_key"

[Migration.Operations.Field.Annotations.Value]
TableName = "lobby"
TableName = "chatroom"
ColumnName = "uuid"
OnDelete = "Cascade"
OnUpdate = "Cascade"
Expand All @@ -492,17 +494,17 @@ Type = "not_null"

[[Migration.Operations]]
Type = "CreateField"
Model = "chatroommember"
Model = "invite"

[Migration.Operations.Field]
Name = "chat_room"
Name = "from"
Type = "varbinary"

[[Migration.Operations.Field.Annotations]]
Type = "foreign_key"

[Migration.Operations.Field.Annotations.Value]
TableName = "chatroom"
TableName = "account"
ColumnName = "uuid"
OnDelete = "Cascade"
OnUpdate = "Cascade"
Expand All @@ -512,10 +514,10 @@ Type = "not_null"

[[Migration.Operations]]
Type = "CreateField"
Model = "chatroommember"
Model = "invite"

[Migration.Operations.Field]
Name = "member"
Name = "to"
Type = "varbinary"

[[Migration.Operations.Field.Annotations]]
Expand All @@ -532,17 +534,17 @@ Type = "not_null"

[[Migration.Operations]]
Type = "CreateField"
Model = "friend"
Model = "invite"

[Migration.Operations.Field]
Name = "from"
Name = "lobby"
Type = "varbinary"

[[Migration.Operations.Field.Annotations]]
Type = "foreign_key"

[Migration.Operations.Field.Annotations.Value]
TableName = "account"
TableName = "lobby"
ColumnName = "uuid"
OnDelete = "Cascade"
OnUpdate = "Cascade"
Expand All @@ -552,10 +554,10 @@ Type = "not_null"

[[Migration.Operations]]
Type = "CreateField"
Model = "friend"
Model = "chatroommessage"

[Migration.Operations.Field]
Name = "to"
Name = "sender"
Type = "varbinary"

[[Migration.Operations.Field.Annotations]]
Expand All @@ -572,7 +574,7 @@ Type = "not_null"

[[Migration.Operations]]
Type = "CreateField"
Model = "friend"
Model = "chatroommessage"

[Migration.Operations.Field]
Name = "chat_room"
Expand All @@ -587,19 +589,22 @@ ColumnName = "uuid"
OnDelete = "Cascade"
OnUpdate = "Cascade"

[[Migration.Operations.Field.Annotations]]
Type = "not_null"

[[Migration.Operations]]
Type = "CreateField"
Model = "lobbyaccount"
Model = "gameaccount"

[Migration.Operations.Field]
Name = "lobby"
Name = "game"
Type = "varbinary"

[[Migration.Operations.Field.Annotations]]
Type = "foreign_key"

[Migration.Operations.Field.Annotations.Value]
TableName = "lobby"
TableName = "game"
ColumnName = "uuid"
OnDelete = "Cascade"
OnUpdate = "Cascade"
Expand All @@ -609,7 +614,7 @@ Type = "not_null"

[[Migration.Operations]]
Type = "CreateField"
Model = "lobbyaccount"
Model = "gameaccount"

[Migration.Operations.Field]
Name = "player"
Expand All @@ -629,17 +634,17 @@ Type = "not_null"

[[Migration.Operations]]
Type = "CreateField"
Model = "chatroommessage"
Model = "lobbyaccount"

[Migration.Operations.Field]
Name = "sender"
Name = "lobby"
Type = "varbinary"

[[Migration.Operations.Field.Annotations]]
Type = "foreign_key"

[Migration.Operations.Field.Annotations.Value]
TableName = "account"
TableName = "lobby"
ColumnName = "uuid"
OnDelete = "Cascade"
OnUpdate = "Cascade"
Expand All @@ -649,17 +654,17 @@ Type = "not_null"

[[Migration.Operations]]
Type = "CreateField"
Model = "chatroommessage"
Model = "lobbyaccount"

[Migration.Operations.Field]
Name = "chat_room"
Name = "player"
Type = "varbinary"

[[Migration.Operations.Field.Annotations]]
Type = "foreign_key"

[Migration.Operations.Field.Annotations.Value]
TableName = "chatroom"
TableName = "account"
ColumnName = "uuid"
OnDelete = "Cascade"
OnUpdate = "Cascade"
Expand Down
4 changes: 4 additions & 0 deletions src/models/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ pub struct ChatRoom {

/// A backref to the members of a specific chatroom
pub messages: BackRef<field!(ChatRoomMessage::F.chat_room)>,

/// The uuid of the most recent message
pub last_message_uuid: Option<Uuid>,
}

#[derive(Patch)]
#[rorm(model = "ChatRoom")]
pub(crate) struct ChatRoomInsert {
pub(crate) uuid: Uuid,
pub(crate) last_message_uuid: Option<Uuid>,
}

/// The member <-> chatroom relation
Expand Down
Loading

0 comments on commit ca1ad42

Please sign in to comment.