aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/db/models.py')
-rw-r--r--mediagoblin/db/models.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py
index 9f4a144c..d7ddc55d 100644
--- a/mediagoblin/db/models.py
+++ b/mediagoblin/db/models.py
@@ -243,6 +243,7 @@ class User(Base, UserMixin):
created = Column(DateTime, nullable=False, default=datetime.datetime.utcnow)
updated = Column(DateTime, nullable=False, default=datetime.datetime.utcnow)
+ deleted = Column(DateTime, nullable=True)
location = Column(Integer, ForeignKey("core__locations.id"))
@@ -254,6 +255,10 @@ class User(Base, UserMixin):
'polymorphic_on': type,
}
+ __model_args__ = {
+ 'deletion': Base.SOFT_DELETE,
+ }
+
def delete(self, **kwargs):
"""Deletes a User and all related entries/comments/files/..."""
# Collections get deleted by relationships.
@@ -516,6 +521,7 @@ class MediaEntry(Base, MediaEntryMixin):
created = Column(DateTime, nullable=False, default=datetime.datetime.utcnow,
index=True)
updated = Column(DateTime, nullable=False, default=datetime.datetime.utcnow)
+ deleted = Column(DateTime, nullable=True)
fail_error = Column(Unicode)
fail_metadata = Column(JSONEncoded)
@@ -909,6 +915,7 @@ class MediaComment(Base, MediaCommentMixin):
Integer, ForeignKey(MediaEntry.id), nullable=False, index=True)
actor = Column(Integer, ForeignKey(User.id), nullable=False)
created = Column(DateTime, nullable=False, default=datetime.datetime.utcnow)
+ deleted = Column(DateTime, nullable=True)
content = Column(UnicodeText, nullable=False)
location = Column(Integer, ForeignKey("core__locations.id"))
get_location = relationship("Location", lazy="joined")
@@ -934,6 +941,10 @@ class MediaComment(Base, MediaCommentMixin):
lazy="dynamic",
cascade="all, delete-orphan"))
+ __model_args__ = {
+ "deletion": Base.SOFT_DELETE,
+ }
+
def serialize(self, request):
""" Unserialize to python dictionary for API """
href = request.urlgen(
@@ -1010,6 +1021,7 @@ class Collection(Base, CollectionMixin):
created = Column(DateTime, nullable=False, default=datetime.datetime.utcnow,
index=True)
updated = Column(DateTime, nullable=False, default=datetime.datetime.utcnow)
+ deleted = Column(DateTime, nullable=True)
description = Column(UnicodeText)
actor = Column(Integer, ForeignKey(User.id), nullable=False)
num_items = Column(Integer, default=0)
@@ -1028,9 +1040,13 @@ class Collection(Base, CollectionMixin):
backref=backref("collections",
cascade="all, delete-orphan"))
__table_args__ = (
- UniqueConstraint('actor', 'slug'),
+ UniqueConstraint("actor", "slug"),
{})
+ __model_args__ = {
+ "delete": Base.SOFT_DELETE,
+ }
+
# These are the types, It's strongly suggested if new ones are invented they
# are prefixed to ensure they're unique from other types. Any types used in
# the main mediagoblin should be prefixed "core-"
@@ -1422,8 +1438,13 @@ class Generator(Base):
name = Column(Unicode, nullable=False)
published = Column(DateTime, default=datetime.datetime.utcnow)
updated = Column(DateTime, default=datetime.datetime.utcnow)
+ deleted = Column(DateTime, nullable=True)
object_type = Column(Unicode, nullable=False)
+ __model_args__ = {
+ "deletion": Base.SOFT_DELETE,
+ }
+
def __repr__(self):
return "<{klass} {name}>".format(
klass=self.__class__.__name__,
@@ -1464,6 +1485,8 @@ class Activity(Base, ActivityMixin):
nullable=False)
published = Column(DateTime, nullable=False, default=datetime.datetime.utcnow)
updated = Column(DateTime, nullable=False, default=datetime.datetime.utcnow)
+ deleted = Column(DateTime, nullable=True)
+
verb = Column(Unicode, nullable=False)
content = Column(Unicode, nullable=True)
title = Column(Unicode, nullable=True)
@@ -1488,6 +1511,10 @@ class Activity(Base, ActivityMixin):
cascade="all, delete-orphan"))
get_generator = relationship(Generator)
+ __model_args__ = {
+ "deletion": Base.SOFT_DELETE,
+ }
+
def __repr__(self):
if self.content is None:
return "<{klass} verb:{verb}>".format(