From 8ab74eb306c611dea158d3e9e6b849bfae1ee871 Mon Sep 17 00:00:00 2001 From: codl Date: Thu, 31 Aug 2017 21:22:22 +0200 Subject: [PATCH] default next_delete to null --- ...1ef02e66382_default_next_delete_to_null.py | 26 +++++++++++++++++++ model.py | 7 ++--- 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 migrations/versions/41ef02e66382_default_next_delete_to_null.py diff --git a/migrations/versions/41ef02e66382_default_next_delete_to_null.py b/migrations/versions/41ef02e66382_default_next_delete_to_null.py new file mode 100644 index 0000000..416f628 --- /dev/null +++ b/migrations/versions/41ef02e66382_default_next_delete_to_null.py @@ -0,0 +1,26 @@ +"""default next_delete to null + +Revision ID: 41ef02e66382 +Revises: f95af1a8d89f +Create Date: 2017-08-31 21:19:44.304952 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '41ef02e66382' +down_revision = 'f95af1a8d89f' +branch_labels = None +depends_on = None + + +def upgrade(): + op.alter_column('accounts', 'next_delete', server_default=None) + op.execute("UPDATE accounts SET next_delete = NULL where next_delete = 'epoch';") + + +def downgrade(): + op.alter_column('accounts', 'next_delete', server_default='epoch') + op.execute("UPDATE accounts SET next_delete = 'epoch' where next_delete IS NULL;") diff --git a/model.py b/model.py index de10b5c..79189ae 100644 --- a/model.py +++ b/model.py @@ -97,10 +97,8 @@ class Account(TimestampMixin, RemoteIDMixin): server_default='epoch', index=True) last_refresh = db.Column(db.DateTime(timezone=True), server_default='epoch', index=True) - last_delete = db.Column(db.DateTime(timezone=True), - index=True) - next_delete = db.Column(db.DateTime(timezone=True), - server_default='epoch', index=True) + last_delete = db.Column(db.DateTime(timezone=True), index=True) + next_delete = db.Column(db.DateTime(timezone=True), index=True) def touch_fetch(self): self.last_fetch = db.func.now() @@ -142,7 +140,6 @@ class Account(TimestampMixin, RemoteIDMixin): datetime.now(timezone.utc) + self.policy_delete_every) return enable - # backref: tokens # backref: twitter_archives # backref: posts