From c2e7b07e92817fbdcce524288f138aa9bcb31c85 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 20 2016 06:33:37 +0000 Subject: Add a _notifications column to the projects table --- diff --git a/alembic/versions/368fd931cf7f_add_the_notifications_column_to_projects.py b/alembic/versions/368fd931cf7f_add_the_notifications_column_to_projects.py new file mode 100644 index 0000000..cb5825b --- /dev/null +++ b/alembic/versions/368fd931cf7f_add_the_notifications_column_to_projects.py @@ -0,0 +1,29 @@ +"""Add the notifications column to projects + +Revision ID: 368fd931cf7f +Revises: 36386a60b3fd +Create Date: 2016-09-18 18:51:09.625322 + +""" + +# revision identifiers, used by Alembic. +revision = '368fd931cf7f' +down_revision = '36386a60b3fd' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + ''' Add the column notifications to the table projects. + ''' + op.add_column( + 'projects', + sa.Column('_notifications', sa.String(255), nullable=True) + ) + + +def downgrade(): + ''' Add the column notifications to the table projects. + ''' + op.drop_column('projects', '_notifications') diff --git a/pagure/lib/model.py b/pagure/lib/model.py index f46dc06..0e62ad6 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -319,6 +319,7 @@ class Project(BASE): _priorities = sa.Column(sa.Text, nullable=True) _milestones = sa.Column(sa.Text, nullable=True) _reports = sa.Column(sa.Text, nullable=True) + _notifications = sa.Column(sa.Text, nullable=True) date_created = sa.Column(sa.DateTime, nullable=False, default=datetime.datetime.utcnow) @@ -442,6 +443,23 @@ class Project(BASE): self._priorities = json.dumps(priorities) @property + def notifications(self): + """ Return the dict stored as string in the database as an actual + dict object. + """ + notifications = {} + + if self._notifications: + notifications = json.loads(self._notifications) + + return notifications + + @notifications.setter + def notifications(self, notifications): + ''' Ensures the notifications are properly saved. ''' + self._notifications = json.dumps(notifications) + + @property def reports(self): """ Return the dict stored as string in the database as an actual dict object.