You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: mcpgateway/db.py
+21-3Lines changed: 21 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1193,10 +1193,28 @@ class UserRole(Base):
1193
1193
1194
1194
__tablename__="user_roles"
1195
1195
__table_args__= (
1196
-
# Partial unique indexes: only one active assignment per (user, role, scope, scope_id) combination
1196
+
# Partial unique indexes: only one active NON-EXPIRED assignment per (user, role, scope, scope_id) combination
1197
1197
# Need two separate indexes to handle NULL vs non-NULL scope_id cases (SQL NULL != NULL semantics)
1198
-
Index("uq_user_roles_email_role_scope_null_active", "user_email", "role_id", "scope", unique=True, postgresql_where=text("scope_id IS NULL AND is_active = true"), sqlite_where=text("scope_id IS NULL AND is_active = 1")),
1199
-
Index("uq_user_roles_email_role_scope_id_active", "user_email", "role_id", "scope", "scope_id", unique=True, postgresql_where=text("scope_id IS NOT NULL AND is_active = true"), sqlite_where=text("scope_id IS NOT NULL AND is_active = 1")),
1198
+
# Excludes expired assignments: is_active = true AND (expires_at IS NULL OR expires_at > CURRENT_TIMESTAMP)
1199
+
Index(
1200
+
"uq_user_roles_email_role_scope_null_active",
1201
+
"user_email",
1202
+
"role_id",
1203
+
"scope",
1204
+
unique=True,
1205
+
postgresql_where=text("scope_id IS NULL AND is_active = true AND (expires_at IS NULL OR expires_at > CURRENT_TIMESTAMP)"),
1206
+
sqlite_where=text("scope_id IS NULL AND is_active = 1 AND (expires_at IS NULL OR expires_at > datetime('now'))"),
1207
+
),
1208
+
Index(
1209
+
"uq_user_roles_email_role_scope_id_active",
1210
+
"user_email",
1211
+
"role_id",
1212
+
"scope",
1213
+
"scope_id",
1214
+
unique=True,
1215
+
postgresql_where=text("scope_id IS NOT NULL AND is_active = true AND (expires_at IS NULL OR expires_at > CURRENT_TIMESTAMP)"),
1216
+
sqlite_where=text("scope_id IS NOT NULL AND is_active = 1 AND (expires_at IS NULL OR expires_at > datetime('now'))"),
0 commit comments