aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db/migrations.py
diff options
context:
space:
mode:
authorJessica Tallon <tsyesika@tsyesika.se>2015-10-01 15:59:20 +0200
committerJessica Tallon <tsyesika@tsyesika.se>2015-10-07 14:40:44 +0200
commitbc75a6532712e4b9b0f6d8b5bbd93db3ef58335d (patch)
tree00cf85c4b4f7ab9ce6eb85d4017a202c730b2384 /mediagoblin/db/migrations.py
parent30852fda1c119e6031914b983920898cd57d5aa9 (diff)
downloadmediagoblin-bc75a6532712e4b9b0f6d8b5bbd93db3ef58335d.tar.lz
mediagoblin-bc75a6532712e4b9b0f6d8b5bbd93db3ef58335d.tar.xz
mediagoblin-bc75a6532712e4b9b0f6d8b5bbd93db3ef58335d.zip
Add Graveyard model
This adds the Graveyard model which is used when a model is deleted, it stores the important "shell" information on the model so it can hard-delete the real object. It also remaps the GenericModelReference references to the new Graveyard model. This also moves the soft deletion setting from __model_args__ to "deletion_mode" on the model.
Diffstat (limited to 'mediagoblin/db/migrations.py')
-rw-r--r--mediagoblin/db/migrations.py73
1 files changed, 16 insertions, 57 deletions
diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py
index 019eb338..36ad736a 100644
--- a/mediagoblin/db/migrations.py
+++ b/mediagoblin/db/migrations.py
@@ -1821,69 +1821,28 @@ def federation_actor(db):
# commit changes to db.
db.commit()
-@RegisterMigration(39, MIGRATIONS)
-def federation_soft_deletion(db):
- """ Introduces soft deletion to models
+class Graveyard_V0(declarative_base()):
+ """ Where models come to die """
+ __tablename__ = "core__graveyard"
- 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)
+ id = Column(Integer, primary_key=True)
+ public_id = Column(Unicode, nullable=True, unique=True)
- # User Model
- user_table = inspect_table(metadata, "core__users")
- user_deleted_column = Column(
- "deleted",
- DateTime,
- nullable=True
- )
- user_deleted_column.create(user_table)
+ deleted = Column(DateTime, nullable=False)
+ object_type = Column(Unicode, nullable=False)
- # 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)
+ actor_id = Column(Integer, ForeignKey(GenericModelReference_V0.id))
- # 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)
+@RegisterMigration(39, MIGRATIONS)
+def federation_graveyard(db):
+ """ Introduces soft deletion to models
- # Generator
- generator_table = inspect_table(metadata, "core__generators")
- generator_deleted_column = Column(
- "deleted",
- DateTime,
- nullable=True
- )
- generator_deleted_column.create(generator_table)
+ This adds a Graveyard model which is used to copy (soft-)deleted models to.
+ """
+ metadata = MetaData(bind=db.bind)
- # Activity
- activity_table = inspect_table(metadata, "core__activities")
- activity_deleted_column = Column(
- "deleted",
- DateTime,
- nullable=True
- )
- activity_deleted_column.create(activity_table)
+ # Create the graveyard table
+ Graveyard_V0.__table__.create(db.bind)
# Commit changes to the db
db.commit()