Skip to content

Commit 4731d3c

Browse files
committed
Introduce optional human_name column on compat_sessions
1 parent 60b6d2f commit 4731d3c

File tree

6 files changed

+44
-9
lines changed

6 files changed

+44
-9
lines changed

crates/data-model/src/compat/session.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ pub struct CompatSession {
7272
pub state: CompatSessionState,
7373
pub user_id: Ulid,
7474
pub device: Option<Device>,
75+
pub human_name: Option<String>,
7576
pub user_session_id: Option<Ulid>,
7677
pub created_at: DateTime<Utc>,
7778
pub is_synapse_admin: bool,
Lines changed: 15 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Copyright 2025 New Vector Ltd.
2+
--
3+
-- SPDX-License-Identifier: AGPL-3.0-only
4+
-- Please see LICENSE in the repository root for full details.
5+
6+
ALTER TABLE compat_sessions
7+
-- Stores a human-readable name for the device.
8+
-- syn2mas behaviour: Will be populated from the device name in Synapse.
9+
ADD COLUMN human_name TEXT;

crates/storage-pg/src/app_session.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ mod priv_ {
6464
pub(super) user_id: Option<Uuid>,
6565
pub(super) scope_list: Option<Vec<String>>,
6666
pub(super) device_id: Option<String>,
67+
pub(super) human_name: Option<String>,
6768
pub(super) created_at: DateTime<Utc>,
6869
pub(super) finished_at: Option<DateTime<Utc>>,
6970
pub(super) is_synapse_admin: Option<bool>,
@@ -91,6 +92,7 @@ impl TryFrom<AppSessionLookup> for AppSession {
9192
user_id,
9293
scope_list,
9394
device_id,
95+
human_name,
9496
created_at,
9597
finished_at,
9698
is_synapse_admin,
@@ -141,6 +143,7 @@ impl TryFrom<AppSessionLookup> for AppSession {
141143
state,
142144
user_id: user_id.into(),
143145
device,
146+
human_name,
144147
user_session_id,
145148
created_at,
146149
is_synapse_admin,
@@ -294,6 +297,7 @@ impl AppSessionRepository for PgAppSessionRepository<'_> {
294297
AppSessionLookupIden::ScopeList,
295298
)
296299
.expr_as(Expr::cust("NULL"), AppSessionLookupIden::DeviceId)
300+
.expr_as(Expr::cust("NULL"), AppSessionLookupIden::HumanName)
297301
.expr_as(
298302
Expr::col((OAuth2Sessions::Table, OAuth2Sessions::CreatedAt)),
299303
AppSessionLookupIden::CreatedAt,
@@ -343,6 +347,10 @@ impl AppSessionRepository for PgAppSessionRepository<'_> {
343347
Expr::col((CompatSessions::Table, CompatSessions::DeviceId)),
344348
AppSessionLookupIden::DeviceId,
345349
)
350+
.expr_as(
351+
Expr::col((CompatSessions::Table, CompatSessions::HumanName)),
352+
AppSessionLookupIden::HumanName,
353+
)
346354
.expr_as(
347355
Expr::col((CompatSessions::Table, CompatSessions::CreatedAt)),
348356
AppSessionLookupIden::CreatedAt,

crates/storage-pg/src/compat/session.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl<'c> PgCompatSessionRepository<'c> {
4848
struct CompatSessionLookup {
4949
compat_session_id: Uuid,
5050
device_id: Option<String>,
51+
human_name: Option<String>,
5152
user_id: Uuid,
5253
user_session_id: Option<Uuid>,
5354
created_at: DateTime<Utc>,
@@ -85,6 +86,7 @@ impl TryFrom<CompatSessionLookup> for CompatSession {
8586
user_id: value.user_id.into(),
8687
user_session_id: value.user_session_id.map(Ulid::from),
8788
device,
89+
human_name: value.human_name,
8890
created_at: value.created_at,
8991
is_synapse_admin: value.is_synapse_admin,
9092
user_agent: value.user_agent.map(UserAgent::parse),
@@ -101,6 +103,7 @@ impl TryFrom<CompatSessionLookup> for CompatSession {
101103
struct CompatSessionAndSsoLoginLookup {
102104
compat_session_id: Uuid,
103105
device_id: Option<String>,
106+
human_name: Option<String>,
104107
user_id: Uuid,
105108
user_session_id: Option<Uuid>,
106109
created_at: DateTime<Utc>,
@@ -143,6 +146,7 @@ impl TryFrom<CompatSessionAndSsoLoginLookup> for (CompatSession, Option<CompatSs
143146
state,
144147
user_id: value.user_id.into(),
145148
device,
149+
human_name: value.human_name,
146150
user_session_id: value.user_session_id.map(Ulid::from),
147151
created_at: value.created_at,
148152
is_synapse_admin: value.is_synapse_admin,
@@ -286,6 +290,7 @@ impl CompatSessionRepository for PgCompatSessionRepository<'_> {
286290
r#"
287291
SELECT compat_session_id
288292
, device_id
293+
, human_name
289294
, user_id
290295
, user_session_id
291296
, created_at
@@ -356,6 +361,7 @@ impl CompatSessionRepository for PgCompatSessionRepository<'_> {
356361
state: CompatSessionState::default(),
357362
user_id: user.id,
358363
device: Some(device),
364+
human_name: None,
359365
user_session_id: browser_session.map(|s| s.id),
360366
created_at,
361367
is_synapse_admin,
@@ -453,6 +459,10 @@ impl CompatSessionRepository for PgCompatSessionRepository<'_> {
453459
Expr::col((CompatSessions::Table, CompatSessions::DeviceId)),
454460
CompatSessionAndSsoLoginLookupIden::DeviceId,
455461
)
462+
.expr_as(
463+
Expr::col((CompatSessions::Table, CompatSessions::HumanName)),
464+
CompatSessionAndSsoLoginLookupIden::HumanName,
465+
)
456466
.expr_as(
457467
Expr::col((CompatSessions::Table, CompatSessions::UserId)),
458468
CompatSessionAndSsoLoginLookupIden::UserId,

crates/storage-pg/src/iden.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub enum CompatSessions {
4343
CompatSessionId,
4444
UserId,
4545
DeviceId,
46+
HumanName,
4647
UserSessionId,
4748
CreatedAt,
4849
FinishedAt,

0 commit comments

Comments
 (0)