diff options
author | Jessica Tallon <tsyesika@tsyesika.se> | 2015-10-01 13:23:33 +0200 |
---|---|---|
committer | Jessica Tallon <tsyesika@tsyesika.se> | 2015-10-07 14:40:44 +0200 |
commit | 30852fda1c119e6031914b983920898cd57d5aa9 (patch) | |
tree | e7727c3425d97ecae95f7b738023475f8ecbe11a /mediagoblin/db/migrations.py | |
parent | 0f3bf8d4b180ffd1907d1578e087522aad7d9158 (diff) | |
download | mediagoblin-30852fda1c119e6031914b983920898cd57d5aa9.tar.lz mediagoblin-30852fda1c119e6031914b983920898cd57d5aa9.tar.xz mediagoblin-30852fda1c119e6031914b983920898cd57d5aa9.zip |
Add the __model_args__ deletion code
This adds the "deleted" fields to the models as well as a new
__model_args__ section whcih supports the option for changing the
deletion type. Deletion is now handled by choosing a deletion method
based on the __model_args__["deletion"] setting, for example if it's
soft deletion it will call Model.soft_delete()
Diffstat (limited to 'mediagoblin/db/migrations.py')
-rw-r--r-- | mediagoblin/db/migrations.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py index 4e9d3a2a..019eb338 100644 --- a/mediagoblin/db/migrations.py +++ b/mediagoblin/db/migrations.py @@ -1820,3 +1820,70 @@ def federation_actor(db): # commit changes to db. db.commit() + +@RegisterMigration(39, MIGRATIONS) +def federation_soft_deletion(db): + """ Introduces soft deletion to models + + This adds a deleted DateTime column which represents if the model is + deleted and if so, when. With this change comes changes on the models + that soft delete the models rather than the previous hard deletion. + """ + metadata = MetaData(bind=db.bind) + + # User Model + user_table = inspect_table(metadata, "core__users") + user_deleted_column = Column( + "deleted", + DateTime, + nullable=True + ) + user_deleted_column.create(user_table) + + # MediaEntry + media_entry_table = inspect_table(metadata, "core__media_entries") + me_deleted_column = Column( + "deleted", + DateTime, + nullable=True + ) + me_deleted_column.create(media_entry_table) + + # MediaComment + media_comment_table = inspect_table(metadata, "core__media_comments") + mc_deleted_column = Column( + "deleted", + DateTime, + nullable=True + ) + mc_deleted_column.create(media_comment_table) + + # Collection + collection_table = inspect_table(metadata, "core__collections") + collection_deleted_column = Column( + "deleted", + DateTime, + nullable=True + ) + collection_deleted_column.create(collection_table) + + # Generator + generator_table = inspect_table(metadata, "core__generators") + generator_deleted_column = Column( + "deleted", + DateTime, + nullable=True + ) + generator_deleted_column.create(generator_table) + + # Activity + activity_table = inspect_table(metadata, "core__activities") + activity_deleted_column = Column( + "deleted", + DateTime, + nullable=True + ) + activity_deleted_column.create(activity_table) + + # Commit changes to the db + db.commit() |