diff --git a/storyboard/db/api/comments.py b/storyboard/db/api/comments.py index b0a070c8..4a76ea65 100644 --- a/storyboard/db/api/comments.py +++ b/storyboard/db/api/comments.py @@ -26,6 +26,12 @@ def comment_create(values): def comment_update(comment_id, values): + comment = api_base.entity_get(models.Comment, comment_id) + old_dict = { + 'comment_id': comment_id, + 'content': comment.content + } + api_base.entity_create(models.HistoricalComment, old_dict) return api_base.entity_update(models.Comment, comment_id, values) diff --git a/storyboard/db/migration/alembic_migrations/versions/059_add_a_table_for_comment_history.py b/storyboard/db/migration/alembic_migrations/versions/059_add_a_table_for_comment_history.py new file mode 100644 index 00000000..388c0393 --- /dev/null +++ b/storyboard/db/migration/alembic_migrations/versions/059_add_a_table_for_comment_history.py @@ -0,0 +1,49 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +"""Add a table for comment history + +Revision ID: 059 +Revises: 058 +Create Date: 2016-06-21 14:00:20.515139 + +""" + +# revision identifiers, used by Alembic. +revision = '059' +down_revision = '058' + + +from alembic import op +import sqlalchemy as sa + +from storyboard.db.decorators import UTCDateTime +from storyboard.db.models import MYSQL_MEDIUM_TEXT + + +def upgrade(active_plugins=None, options=None): + op.create_table( + 'comments_history', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', UTCDateTime(), nullable=True), + sa.Column('updated_at', UTCDateTime(), nullable=True), + sa.Column('content', MYSQL_MEDIUM_TEXT, nullable=True), + sa.Column('comment_id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['comment_id'], ['comments.id'], + name='fk_comment_id'), + sa.PrimaryKeyConstraint('id') + ) + + +def downgrade(active_plugins=None, options=None): + op.drop_table('comments_history') diff --git a/storyboard/db/models.py b/storyboard/db/models.py index 302b970c..018a0e0f 100644 --- a/storyboard/db/models.py +++ b/storyboard/db/models.py @@ -508,6 +508,15 @@ class Comment(FullText, ModelBuilder, Base): parent = relationship('Comment', remote_side=[id], backref='children') +class HistoricalComment(FullText, ModelBuilder, Base): + __tablename__ = 'comments_history' + __fulltext_columns__ = ['content'] + + content = Column(MYSQL_MEDIUM_TEXT) + comment_id = Column(Integer, ForeignKey('comments.id'), nullable=False) + current = relationship(Comment, backref='history') + + # Subscription and notifications class Subscription(ModelBuilder, Base):