@@ -142,21 +142,6 @@ class Meta:
142142
143143 oauth_name = UnicodeAttribute (hash_key = True )
144144
145- class UserIdIndex (GlobalSecondaryIndex ):
146- """Enable the `user_id` attribute to be a Global Secondary Index.
147-
148- Args:
149- GlobalSecondaryIndex (_type_): The Global Secondary Index base class.
150- """
151-
152- class Meta :
153- """The metadata for the Global Secondary Index."""
154-
155- index_name = "user_id-index"
156- projection = AllProjection ()
157-
158- user_id = GUID (hash_key = True )
159-
160145 if TYPE_CHECKING : # pragma: no cover
161146 id : ID
162147 oauth_name : str
@@ -176,7 +161,6 @@ class Meta:
176161 # Global Secondary Index
177162 account_id_index = AccountIdIndex ()
178163 oauth_name_index = OAuthNameIndex ()
179- user_id_index = UserIdIndex ()
180164
181165
182166class DynamoDBBaseOAuthAccountTableUUID (DynamoDBBaseOAuthAccountTable [UUID_ID ]):
@@ -186,13 +170,32 @@ class DynamoDBBaseOAuthAccountTableUUID(DynamoDBBaseOAuthAccountTable[UUID_ID]):
186170 DynamoDBBaseOAuthAccountTable (_type_): The underlying table object.
187171 """
188172
173+ # MANDATORY GSI (MUST BE IMPLEMENTED)
174+ class UserIdIndex (GlobalSecondaryIndex ):
175+ """Enable the `user_id` attribute to be a Global Secondary Index.
176+
177+ Args:
178+ GlobalSecondaryIndex (_type_): The Global Secondary Index base class.
179+ """
180+
181+ class Meta :
182+ """The metadata for the Global Secondary Index."""
183+
184+ index_name = "user_id-index"
185+ projection = AllProjection ()
186+
187+ user_id = GUID (hash_key = True )
188+
189189 if TYPE_CHECKING : # pragma: no cover
190190 id : UUID_ID
191191 user_id : UUID_ID
192192 else :
193193 id : GUID = GUID (hash_key = True , default = uuid .uuid4 )
194194 user_id : GUID = GUID (null = False )
195195
196+ # Global Secondary Index
197+ user_id_index = UserIdIndex ()
198+
196199
197200class DynamoDBUserDatabase (Generic [UP , ID ], BaseUserDatabase [UP , ID ]):
198201 """
@@ -240,6 +243,13 @@ async def _hydrate_oauth_accounts(
240243
241244 user .oauth_accounts = [] # type: ignore
242245
246+ if not hasattr (self .oauth_account_table , "user_id_index" ) or not isinstance (
247+ self .oauth_account_table .user_id_index , # type: ignore
248+ GlobalSecondaryIndex ,
249+ ):
250+ raise ValueError (
251+ "Attribute 'user_id_index' not found: OAuthAccount table scheme must implement a Global Secondary Index for attribute 'user_id'."
252+ )
243253 async for oauth_acc in self .oauth_account_table .user_id_index .query ( # type: ignore
244254 user .id ,
245255 consistent_read = instant_update ,
0 commit comments