diff --git a/createdb.py b/createdb.py deleted file mode 100644 index cc5c501..0000000 --- a/createdb.py +++ /dev/null @@ -1,5 +0,0 @@ -import forget - -from app import db - -db.create_all() diff --git a/migrations/versions/e036b007017c_.py b/migrations/versions/e036b007017c_.py new file mode 100644 index 0000000..033dd65 --- /dev/null +++ b/migrations/versions/e036b007017c_.py @@ -0,0 +1,28 @@ +"""empty message + +Revision ID: e036b007017c +Revises: 9fab742962ef +Create Date: 2017-08-01 22:45:28.450097 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'e036b007017c' +down_revision = '9fab742962ef' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('accounts', sa.Column('last_delete', sa.DateTime(), server_default='epoch', nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('accounts', 'last_delete') + # ### end Alembic commands ### diff --git a/model.py b/model.py index 1f38ec6..6165e2f 100644 --- a/model.py +++ b/model.py @@ -51,18 +51,26 @@ class Account(TimestampMixin, RemoteIDMixin): remote_avatar_url = db.Column(db.String) last_fetch = db.Column(db.DateTime, server_default='epoch') + last_delete = db.Column(db.DateTime, server_default='epoch') def touch_fetch(self): self.last_fetch = db.func.now() + @db.validates('policy_keep_younger', 'policy_delete_every') + def validate_intervals(self, key, value): + if not (value == timedelta(0) or value >= timedelta(minutes=1)): + value = timedelta(minutes=1) + return value + # backref: tokens # backref: twitter_archives + # backref: posts def __repr__(self): return f"" def post_count(self): - return Post.query.filter(Post.author_id == self.id).count() + return Post.query.with_parent(self).count() class Account(Account, db.Model): @@ -93,7 +101,8 @@ class Post(db.Model, TimestampMixin, RemoteIDMixin): body = db.Column(db.String) author_id = db.Column(db.String, db.ForeignKey('accounts.id')) - author = db.relationship(Account) + author = db.relationship(Account, + backref=db.backref('posts', order_by=lambda: db.desc(Post.created_at))) class TwitterArchive(db.Model, TimestampMixin): __tablename__ = 'twitter_archives'