From bcd466234d90be50a6d68d9327a63b101030d486 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 30 2015 10:39:03 +0000 Subject: Add a column updated_on to the pull_requests table This will record the last time the Pull-Request was updated (ie the merge/close date) --- diff --git a/alembic/versions/6190226bed0_add_the_updated_on_column_to_pull_.py b/alembic/versions/6190226bed0_add_the_updated_on_column_to_pull_.py new file mode 100644 index 0000000..6a362b6 --- /dev/null +++ b/alembic/versions/6190226bed0_add_the_updated_on_column_to_pull_.py @@ -0,0 +1,43 @@ +"""Add the updated_on column to pull-requests + +Revision ID: 6190226bed0 +Revises: 257a7ce22682 +Create Date: 2015-09-29 15:32:58.229183 + +""" + +# revision identifiers, used by Alembic. +revision = '6190226bed0' +down_revision = '257a7ce22682' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + ''' Add the column updated_on to the table pull_requests. + ''' + op.add_column( + 'pull_requests', + sa.Column( + 'updated_on', + sa.DateTime, + nullable=True, + default=sa.func.now(), + onupdate=sa.func.now() + ) + ) + + op.execute('''UPDATE "pull_requests" SET updated_on=date_created;''') + + op.alter_column( + 'pull_requests', + column_name='updated_on', + nullable=False, + existing_nullable=True) + + +def downgrade(): + ''' Remove the column updated_on from the table pull_requests. + ''' + op.drop_column('pull_requests', 'updated_on') diff --git a/pagure/lib/model.py b/pagure/lib/model.py index f357f8a..ce0a6e2 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -759,6 +759,11 @@ class PullRequest(BASE): date_created = sa.Column(sa.DateTime, nullable=False, default=datetime.datetime.utcnow) + updated_on = sa.Column( + sa.DateTime, + nullable=False, + default=sa.func.now(), + onupdate=sa.func.now()) __table_args__ = ( sa.CheckConstraint( @@ -849,6 +854,7 @@ class PullRequest(BASE): public=public, api=api) if self.project_from else None, 'remote_git': self.remote_git, 'date_created': self.date_created.strftime('%s'), + 'updated_on': self.updated_on.strftime('%s'), 'user': self.user.to_json(public=public), 'assignee': self.assignee.to_json( public=public) if self.assignee else None,