2626# Constants
2727BATCH_SIZE = 1000
2828MEMBER_ROLE_SUFFIX = "member"
29+ SESSION_ENTITY_TYPE = EntityType .SESSION .value
30+ AUTO_RELATION_TYPE = "auto"
2931
3032
3133def _add_entity_type_permissions (db_conn : Connection ) -> None :
@@ -93,7 +95,7 @@ def _add_entity_type_permissions(db_conn: Connection) -> None:
9395 "member_ops" : member_ops ,
9496 "owner_ops" : owner_ops ,
9597 "member_pattern" : f"%{ MEMBER_ROLE_SUFFIX } " ,
96- "entity_type" : EntityType . SESSION . value ,
98+ "entity_type" : SESSION_ENTITY_TYPE ,
9799 },
98100 )
99101
@@ -107,9 +109,6 @@ def _associate_sessions_to_scopes(db_conn: Connection) -> None:
107109
108110 Uses keyset pagination for scalability.
109111 """
110- entity_type = EntityType .SESSION .value
111- relation_type = "auto"
112-
113112 # Process User scope edges
114113 last_id = UUID ("00000000-0000-0000-0000-000000000000" )
115114 while True :
@@ -131,9 +130,9 @@ def _associate_sessions_to_scopes(db_conn: Connection) -> None:
131130 {
132131 "scope_type" : "user" ,
133132 "scope_id" : str (row .user_uuid ),
134- "entity_type" : entity_type ,
133+ "entity_type" : SESSION_ENTITY_TYPE ,
135134 "entity_id" : str (row .id ),
136- "relation_type" : relation_type ,
135+ "relation_type" : AUTO_RELATION_TYPE ,
137136 }
138137 for row in rows
139138 ]
@@ -168,9 +167,9 @@ def _associate_sessions_to_scopes(db_conn: Connection) -> None:
168167 {
169168 "scope_type" : "project" ,
170169 "scope_id" : str (row .group_id ),
171- "entity_type" : entity_type ,
170+ "entity_type" : SESSION_ENTITY_TYPE ,
172171 "entity_id" : str (row .id ),
173- "relation_type" : relation_type ,
172+ "relation_type" : AUTO_RELATION_TYPE ,
174173 }
175174 for row in rows
176175 ]
@@ -187,8 +186,6 @@ def _associate_sessions_to_scopes(db_conn: Connection) -> None:
187186
188187def _remove_session_permissions (db_conn : Connection ) -> None :
189188 """Remove all SESSION entity-type permissions."""
190- entity_type = EntityType .SESSION .value
191-
192189 while True :
193190 # Delete permissions in batches using a parameterized subquery
194191 delete_query = sa .text ("""
@@ -201,16 +198,14 @@ def _remove_session_permissions(db_conn: Connection) -> None:
201198 """ )
202199 result = db_conn .execute (
203200 delete_query ,
204- {"entity_type" : entity_type , "limit" : BATCH_SIZE },
201+ {"entity_type" : SESSION_ENTITY_TYPE , "limit" : BATCH_SIZE },
205202 )
206203 if result .rowcount == 0 :
207204 break
208205
209206
210207def _remove_session_edges (db_conn : Connection ) -> None :
211208 """Remove all SESSION AUTO edges from association_scopes_entities."""
212- entity_type = EntityType .SESSION .value
213-
214209 while True :
215210 # Delete associations in batches using a parameterized subquery
216211 delete_query = sa .text ("""
@@ -223,7 +218,7 @@ def _remove_session_edges(db_conn: Connection) -> None:
223218 """ )
224219 result = db_conn .execute (
225220 delete_query ,
226- {"entity_type" : entity_type , "limit" : BATCH_SIZE },
221+ {"entity_type" : SESSION_ENTITY_TYPE , "limit" : BATCH_SIZE },
227222 )
228223 if result .rowcount == 0 :
229224 break
0 commit comments