@@ -207,9 +207,7 @@ class CalendarListEntry(Base):
207207 user_id : Mapped [str ] = mapped_column (
208208 ForeignKey ("calendar_users.id" ), nullable = False
209209 )
210- calendar_id : Mapped [str ] = mapped_column (
211- ForeignKey ("calendars.id" ), nullable = False
212- )
210+ calendar_id : Mapped [str ] = mapped_column (ForeignKey ("calendars.id" ), nullable = False )
213211 etag : Mapped [str ] = mapped_column (String (100 ), nullable = False )
214212
215213 # Access role
@@ -226,12 +224,8 @@ class CalendarListEntry(Base):
226224 foreground_color : Mapped [Optional [str ]] = mapped_column (String (10 ), nullable = True )
227225
228226 # Visibility settings
229- hidden : Mapped [bool ] = mapped_column (
230- Boolean , default = False , server_default = "false"
231- )
232- selected : Mapped [bool ] = mapped_column (
233- Boolean , default = True , server_default = "true"
234- )
227+ hidden : Mapped [bool ] = mapped_column (Boolean , default = False , server_default = "false" )
228+ selected : Mapped [bool ] = mapped_column (Boolean , default = True , server_default = "true" )
235229 primary : Mapped [bool ] = mapped_column (
236230 Boolean , default = False , server_default = "false"
237231 )
@@ -276,12 +270,16 @@ class Event(Base):
276270 Index ("ix_event_ical_uid" , "ical_uid" ),
277271 Index ("ix_event_recurring" , "recurring_event_id" ),
278272 Index ("ix_event_updated" , "updated_at" ),
273+ # Composite indexes for common query patterns
274+ Index ("ix_event_cal_status_start" , "calendar_id" , "status" , "start_datetime" ),
275+ Index (
276+ "ix_event_cal_start_end" , "calendar_id" , "start_datetime" , "end_datetime"
277+ ),
278+ Index ("ix_event_cal_updated" , "calendar_id" , "updated_at" ),
279279 )
280280
281281 id : Mapped [str ] = mapped_column (String (1024 ), primary_key = True )
282- calendar_id : Mapped [str ] = mapped_column (
283- ForeignKey ("calendars.id" ), nullable = False
284- )
282+ calendar_id : Mapped [str ] = mapped_column (ForeignKey ("calendars.id" ), nullable = False )
285283 etag : Mapped [str ] = mapped_column (String (100 ), nullable = False )
286284
287285 # Basic info
@@ -312,8 +310,12 @@ class Event(Base):
312310 String (255 ), nullable = True
313311 )
314312 # Google Profile IDs (different from internal user_id)
315- creator_profile_id : Mapped [Optional [str ]] = mapped_column (String (255 ), nullable = True )
316- organizer_profile_id : Mapped [Optional [str ]] = mapped_column (String (255 ), nullable = True )
313+ creator_profile_id : Mapped [Optional [str ]] = mapped_column (
314+ String (255 ), nullable = True
315+ )
316+ organizer_profile_id : Mapped [Optional [str ]] = mapped_column (
317+ String (255 ), nullable = True
318+ )
317319 creator_self : Mapped [bool ] = mapped_column (
318320 Boolean , default = False , server_default = "false"
319321 )
@@ -337,7 +339,9 @@ class Event(Base):
337339
338340 # Recurrence
339341 recurrence : Mapped [Optional [list [str ]]] = mapped_column (JSONB , nullable = True )
340- recurring_event_id : Mapped [Optional [str ]] = mapped_column (String (1024 ), nullable = True )
342+ recurring_event_id : Mapped [Optional [str ]] = mapped_column (
343+ String (1024 ), nullable = True
344+ )
341345 original_start_time : Mapped [Optional [dict [str , Any ]]] = mapped_column (
342346 JSONB , nullable = True
343347 )
@@ -499,7 +503,9 @@ class EventAttendee(Base):
499503 default = AttendeeResponseStatus .needsAction ,
500504 )
501505 comment : Mapped [Optional [str ]] = mapped_column (Text , nullable = True )
502- additional_guests : Mapped [int ] = mapped_column (Integer , default = 0 , server_default = "0" )
506+ additional_guests : Mapped [int ] = mapped_column (
507+ Integer , default = 0 , server_default = "0"
508+ )
503509 # Profile ID (if available)
504510 profile_id : Mapped [Optional [str ]] = mapped_column (String (255 ), nullable = True )
505511
@@ -544,14 +550,14 @@ class AclRule(Base):
544550
545551 __tablename__ = "calendar_acl_rules"
546552 __table_args__ = (
547- UniqueConstraint ("calendar_id" , "scope_type" , "scope_value" , name = "uq_acl_rule" ),
553+ UniqueConstraint (
554+ "calendar_id" , "scope_type" , "scope_value" , name = "uq_acl_rule"
555+ ),
548556 Index ("ix_acl_calendar" , "calendar_id" ),
549557 )
550558
551559 id : Mapped [str ] = mapped_column (String (255 ), primary_key = True )
552- calendar_id : Mapped [str ] = mapped_column (
553- ForeignKey ("calendars.id" ), nullable = False
554- )
560+ calendar_id : Mapped [str ] = mapped_column (ForeignKey ("calendars.id" ), nullable = False )
555561 etag : Mapped [str ] = mapped_column (String (100 ), nullable = False )
556562
557563 role : Mapped [AccessRole ] = mapped_column (
@@ -636,7 +642,9 @@ class Channel(Base):
636642 token : Mapped [Optional [str ]] = mapped_column (String (500 ), nullable = True )
637643 params : Mapped [Optional [dict [str , Any ]]] = mapped_column (JSONB , nullable = True )
638644 # Whether payload is wanted for notifications
639- payload : Mapped [bool ] = mapped_column (Boolean , default = False , server_default = "false" )
645+ payload : Mapped [bool ] = mapped_column (
646+ Boolean , default = False , server_default = "false"
647+ )
640648 # User who created the channel (for ownership validation)
641649 user_id : Mapped [Optional [str ]] = mapped_column (String (255 ), nullable = True )
642650
@@ -654,9 +662,7 @@ class SyncToken(Base):
654662 """
655663
656664 __tablename__ = "calendar_sync_tokens"
657- __table_args__ = (
658- Index ("ix_sync_token_resource" , "resource_type" , "resource_id" ),
659- )
665+ __table_args__ = (Index ("ix_sync_token_resource" , "resource_type" , "resource_id" ),)
660666
661667 id : Mapped [int ] = mapped_column (Integer , primary_key = True , autoincrement = True )
662668 token : Mapped [str ] = mapped_column (String (255 ), unique = True , nullable = False )
0 commit comments