19
19
class Following (Base ): # type: ignore
20
20
__tablename__ = 'mod_followers'
21
21
__table_args__ = (PrimaryKeyConstraint ('user_id' , 'mod_id' , name = 'pk_mod_followers' ), )
22
- mod_id = Column (Integer , ForeignKey ('mod.id' ), index = True )
23
- mod = relationship ('Mod' , back_populates = 'followings' )
24
- user_id = Column (Integer , ForeignKey ('user.id' ), index = True )
25
- user = relationship ('User' , back_populates = 'followings' )
22
+ mod_id = Column (Integer , ForeignKey ('mod.id' , ondelete = 'CASCADE' ), index = True )
23
+ mod = relationship ('Mod' , back_populates = 'followings' , passive_deletes = True )
24
+ user_id = Column (Integer , ForeignKey ('user.id' , ondelete = 'CASCADE' ), index = True )
25
+ user = relationship ('User' , back_populates = 'followings' , passive_deletes = True )
26
26
send_update = Column (Boolean (), default = True , nullable = False )
27
27
send_autoupdate = Column (Boolean (), default = True , nullable = False )
28
28
@@ -37,8 +37,8 @@ def __init__(self, mod: Optional['Mod'] = None, user: Optional['User'] = None,
37
37
class Featured (Base ): # type: ignore
38
38
__tablename__ = 'featured'
39
39
id = Column (Integer , primary_key = True )
40
- mod_id = Column (Integer , ForeignKey ('mod.id' ))
41
- mod = relationship ('Mod' , backref = backref ('featured' , order_by = id ))
40
+ mod_id = Column (Integer , ForeignKey ('mod.id' , ondelete = 'CASCADE' ))
41
+ mod = relationship ('Mod' , backref = backref ('featured' , passive_deletes = True , order_by = id ))
42
42
created = Column (DateTime , default = datetime .now , index = True )
43
43
44
44
def __repr__ (self ) -> str :
@@ -85,7 +85,7 @@ class User(Base): # type: ignore
85
85
bgOffsetX = Column (Integer , default = 0 )
86
86
bgOffsetY = Column (Integer , default = 0 )
87
87
# List of Following objects
88
- followings = relationship ('Following' , back_populates = 'user' )
88
+ followings = relationship ('Following' , back_populates = 'user' , passive_deletes = True )
89
89
# List of mods the user follows
90
90
following = association_proxy ('followings' , 'mod' )
91
91
dark_theme = Column (Boolean , default = False )
@@ -178,8 +178,8 @@ class Game(Base): # type: ignore
178
178
rating = Column (Float ())
179
179
releasedate = Column (DateTime )
180
180
short = Column (Unicode (1024 ))
181
- publisher_id = Column (Integer , ForeignKey ('publisher.id' ))
182
- publisher = relationship ('Publisher' , backref = 'games' )
181
+ publisher_id = Column (Integer , ForeignKey ('publisher.id' , ondelete = 'CASCADE' ))
182
+ publisher = relationship ('Publisher' , backref = backref ( 'games' , passive_deletes = True ) )
183
183
description = Column (Unicode (100000 ))
184
184
short_description = Column (Unicode (1000 ))
185
185
created = Column (DateTime , default = datetime .now , index = True )
@@ -226,10 +226,11 @@ class Mod(Base): # type: ignore
226
226
id = Column (Integer , primary_key = True )
227
227
created = Column (DateTime , default = datetime .now , index = True )
228
228
updated = Column (DateTime , default = datetime .now , index = True )
229
- user_id = Column (Integer , ForeignKey ('user.id' ))
230
- user = relationship ('User' , backref = backref ('mods' , order_by = created ), foreign_keys = user_id )
231
- game_id = Column (Integer , ForeignKey ('game.id' ))
232
- game = relationship ('Game' , backref = 'mods' )
229
+ user_id = Column (Integer , ForeignKey ('user.id' , ondelete = 'CASCADE' ))
230
+ user = relationship ('User' , backref = backref ('mods' , passive_deletes = True , order_by = created ),
231
+ foreign_keys = user_id )
232
+ game_id = Column (Integer , ForeignKey ('game.id' , ondelete = 'CASCADE' ))
233
+ game = relationship ('Game' , backref = backref ('mods' , passive_deletes = True ))
233
234
name = Column (String (100 ), index = True )
234
235
description = Column (Unicode (100000 ))
235
236
short_description = Column (Unicode (1000 ))
@@ -258,7 +259,7 @@ class Mod(Base): # type: ignore
258
259
download_count = Column (Integer , nullable = False , default = 0 )
259
260
ckan = Column (Boolean )
260
261
# List of Following objects
261
- followings = relationship ('Following' , back_populates = 'mod' )
262
+ followings = relationship ('Following' , back_populates = 'mod' , passive_deletes = True )
262
263
# List of users that follow this mods
263
264
followers = association_proxy ('followings' , 'user' )
264
265
@@ -287,10 +288,10 @@ class ModList(Base): # type: ignore
287
288
__tablename__ = 'modlist'
288
289
id = Column (Integer , primary_key = True )
289
290
created = Column (DateTime , default = datetime .now , index = True )
290
- user_id = Column (Integer , ForeignKey ('user.id' ))
291
- user = relationship ('User' , backref = backref ('packs' , order_by = created ))
292
- game_id = Column (Integer , ForeignKey ('game.id' ))
293
- game = relationship ('Game' , backref = 'modlists' )
291
+ user_id = Column (Integer , ForeignKey ('user.id' , ondelete = 'CASCADE' ))
292
+ user = relationship ('User' , backref = backref ('packs' , passive_deletes = True , order_by = created ))
293
+ game_id = Column (Integer , ForeignKey ('game.id' , ondelete = 'CASCADE' ))
294
+ game = relationship ('Game' , backref = backref ( 'modlists' , passive_deletes = True ) )
294
295
# Don't access background directly, use background_url() instead.
295
296
background = Column (String (512 ))
296
297
# Don't access thumbnail directly, use background_thumb() instead.
@@ -336,10 +337,10 @@ def __repr__(self) -> str:
336
337
class SharedAuthor (Base ): # type: ignore
337
338
__tablename__ = 'sharedauthor'
338
339
id = Column (Integer , primary_key = True )
339
- mod_id = Column (Integer , ForeignKey ('mod.id' ))
340
- mod = relationship ('Mod' , backref = 'shared_authors' )
341
- user_id = Column (Integer , ForeignKey ('user.id' ))
342
- user = relationship ('User' , backref = 'shared_authors' )
340
+ mod_id = Column (Integer , ForeignKey ('mod.id' , ondelete = 'CASCADE' ))
341
+ mod = relationship ('Mod' , backref = backref ( 'shared_authors' , passive_deletes = True ) )
342
+ user_id = Column (Integer , ForeignKey ('user.id' , ondelete = 'CASCADE' ))
343
+ user = relationship ('User' , backref = backref ( 'shared_authors' , passive_deletes = True ) )
343
344
accepted = Column (Boolean , default = False )
344
345
345
346
def __repr__ (self ) -> str :
@@ -368,9 +369,10 @@ def __repr__(self) -> str:
368
369
class FollowEvent (Base ): # type: ignore
369
370
__tablename__ = 'followevent'
370
371
id = Column (Integer , primary_key = True )
371
- mod_id = Column (Integer , ForeignKey ('mod.id' ))
372
- mod = relationship ('Mod' ,
373
- backref = backref ('follow_events' , order_by = "desc(FollowEvent.created)" ))
372
+ mod_id = Column (Integer , ForeignKey ('mod.id' , ondelete = 'CASCADE' ))
373
+ mod = relationship ('Mod' , backref = backref ('follow_events' ,
374
+ passive_deletes = True ,
375
+ order_by = "desc(FollowEvent.created)" ))
374
376
events = Column (Integer )
375
377
delta = Column (Integer , default = 0 )
376
378
created = Column (DateTime , default = datetime .now , index = True )
@@ -382,9 +384,10 @@ def __repr__(self) -> str:
382
384
class ReferralEvent (Base ): # type: ignore
383
385
__tablename__ = 'referralevent'
384
386
id = Column (Integer , primary_key = True )
385
- mod_id = Column (Integer , ForeignKey ('mod.id' ))
386
- mod = relationship ('Mod' ,
387
- backref = backref ('referrals' , order_by = "desc(ReferralEvent.created)" ))
387
+ mod_id = Column (Integer , ForeignKey ('mod.id' , ondelete = 'CASCADE' ))
388
+ mod = relationship ('Mod' , backref = backref ('referrals' ,
389
+ passive_deletes = True ,
390
+ order_by = "desc(ReferralEvent.created)" ))
388
391
host = Column (String )
389
392
events = Column (Integer , default = 0 )
390
393
created = Column (DateTime , default = datetime .now , index = True )
@@ -396,13 +399,16 @@ def __repr__(self) -> str:
396
399
class ModVersion (Base ): # type: ignore
397
400
__tablename__ = 'modversion'
398
401
id = Column (Integer , primary_key = True )
399
- mod_id = Column (Integer , ForeignKey ('mod.id' ))
400
- mod = relationship ('Mod' ,
401
- backref = backref ('versions' , order_by = "desc(ModVersion.sort_index)" ),
402
+ mod_id = Column (Integer , ForeignKey ('mod.id' , ondelete = 'CASCADE' ))
403
+ mod = relationship ('Mod' , backref = backref ('versions' ,
404
+ passive_deletes = True ,
405
+ order_by = "desc(ModVersion.sort_index)" ),
402
406
foreign_keys = mod_id )
403
407
friendly_version = Column (String (64 ))
404
- gameversion_id = Column (Integer , ForeignKey ('gameversion.id' ))
405
- gameversion = relationship ('GameVersion' , backref = backref ('mod_versions' , order_by = id ))
408
+ gameversion_id = Column (Integer , ForeignKey ('gameversion.id' , ondelete = 'CASCADE' ))
409
+ gameversion = relationship ('GameVersion' , backref = backref ('mod_versions' ,
410
+ passive_deletes = True ,
411
+ order_by = id ))
406
412
created = Column (DateTime , default = datetime .now )
407
413
download_path = Column (String (512 ))
408
414
changelog = Column (Unicode (10000 ))
@@ -436,8 +442,8 @@ def __repr__(self) -> str:
436
442
class Media (Base ): # type: ignore
437
443
__tablename__ = 'media'
438
444
id = Column (Integer , primary_key = True )
439
- mod_id = Column (Integer , ForeignKey ('mod.id' ))
440
- mod = relationship ('Mod' , backref = backref ('media' , order_by = id ))
445
+ mod_id = Column (Integer , ForeignKey ('mod.id' , ondelete = 'CASCADE' ))
446
+ mod = relationship ('Mod' , backref = backref ('media' , passive_deletes = True , order_by = id ))
441
447
hash = Column (String (12 ))
442
448
type = Column (String (32 ))
443
449
data = Column (String (512 ))
@@ -450,8 +456,8 @@ class GameVersion(Base): # type: ignore
450
456
__tablename__ = 'gameversion'
451
457
id = Column (Integer , primary_key = True )
452
458
friendly_version = Column (String (128 ))
453
- game_id = Column (Integer , ForeignKey ('game.id' ))
454
- game = relationship ('Game' , backref = 'versions' )
459
+ game_id = Column (Integer , ForeignKey ('game.id' , ondelete = 'CASCADE' ))
460
+ game = relationship ('Game' , backref = backref ( 'versions' , passive_deletes = True ) )
455
461
456
462
def __repr__ (self ) -> str :
457
463
return '<Game Version %r>' % self .friendly_version
0 commit comments