Skip to content

Commit

Permalink
adjust column
Browse files Browse the repository at this point in the history
  • Loading branch information
codabrink committed Dec 18, 2024
1 parent 334c066 commit 9b894b5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion xmtp_mls/migrations/2024-12-18-170645_add_dm_id/up.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ALTER TABLE groups ADD COLUMN dm_id TEXT;
ALTER TABLE groups ADD COLUMN last_message_ns BIGINT;
ALTER TABLE groups ADD COLUMN last_message_ns BIGINT NOT NULL DEFAULT (created_at_ns);

-- Fill the dm_id column
UPDATE groups
Expand Down
15 changes: 8 additions & 7 deletions xmtp_mls/src/storage/encrypted_store/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use diesel::{
sql_types::Integer,
};
use serde::{Deserialize, Serialize};
use xmtp_common::time::now_ns;

pub type ID = Vec<u8>;

Expand All @@ -36,14 +37,14 @@ pub struct StoredGroup {
pub added_by_inbox_id: String,
/// The sequence id of the welcome message
pub welcome_id: Option<i64>,
/// The inbox_id of the DM target
pub dm_id: Option<String>,
/// Timestamp of when the last message was sent for this group (updated automatically in a trigger)
pub last_message_ns: Option<i64>,
/// The last time the leaf node encryption key was rotated
pub rotated_at_ns: i64,
/// Enum, [`ConversationType`] signifies the group conversation type which extends to who can access it.
pub conversation_type: ConversationType,
/// The inbox_id of the DM target
pub dm_id: Option<String>,
/// Timestamp of when the last message was sent for this group (updated automatically in a trigger)
pub last_message_ns: i64,
}

impl_fetch!(StoredGroup, groups, Vec<u8>);
Expand All @@ -70,7 +71,7 @@ impl StoredGroup {
welcome_id: Some(welcome_id),
rotated_at_ns: 0,
dm_id,
last_message_ns: None,
last_message_ns: now_ns(),
}
}

Expand All @@ -95,7 +96,7 @@ impl StoredGroup {
welcome_id: None,
rotated_at_ns: 0,
dm_id: dm_id,
last_message_ns: None,
last_message_ns: now_ns(),
}
}

Expand All @@ -116,7 +117,7 @@ impl StoredGroup {
welcome_id: None,
rotated_at_ns: 0,
dm_id: None,
last_message_ns: None,
last_message_ns: now_ns(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion xmtp_mls/src/storage/encrypted_store/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ diesel::table! {
rotated_at_ns -> BigInt,
conversation_type -> Integer,
dm_id -> Nullable<Text>,
last_message_ns -> Nullable<BigInt>,
last_message_ns -> BigInt,
}
}

Expand Down

0 comments on commit 9b894b5

Please sign in to comment.