diff --git a/tildes/alembic/versions/6ede05a0ea23_topic_add_original_url_column.py b/tildes/alembic/versions/6ede05a0ea23_topic_add_original_url_column.py new file mode 100644 index 0000000..4f256ad --- /dev/null +++ b/tildes/alembic/versions/6ede05a0ea23_topic_add_original_url_column.py @@ -0,0 +1,30 @@ +"""Topic: add original_url column + +Revision ID: 6ede05a0ea23 +Revises: 09cfb27cc90e +Create Date: 2018-09-12 18:45:44.768561 + +""" +from alembic import op +import sqlalchemy as sa + +from tildes.models.topic import Topic + + +# revision identifiers, used by Alembic. +revision = "6ede05a0ea23" +down_revision = "09cfb27cc90e" +branch_labels = None +depends_on = None + + +def upgrade(): + op.add_column("topics", sa.Column("original_url", sa.Text(), nullable=True)) + + session = sa.orm.Session(bind=op.get_bind()) + session.query(Topic).update({"original_url": Topic.link}, synchronize_session=False) + session.commit() + + +def downgrade(): + op.drop_column("topics", "original_url") diff --git a/tildes/tildes/models/topic/topic.py b/tildes/tildes/models/topic/topic.py index 207fc5f..afe61bc 100644 --- a/tildes/tildes/models/topic/topic.py +++ b/tildes/tildes/models/topic/topic.py @@ -106,6 +106,7 @@ class Topic(DatabaseModel): _markdown: Optional[str] = deferred(Column("markdown", Text)) rendered_html: Optional[str] = Column(Text) link: Optional[str] = Column(Text) + original_url: Optional[str] = Column(Text) content_metadata: Dict[str, Any] = Column( MutableDict.as_mutable(JSONB(none_as_null=True)) ) @@ -207,6 +208,7 @@ class Topic(DatabaseModel): new_topic = cls._create_base_topic(group, author, title) new_topic.topic_type = TopicType.LINK new_topic.link = link + new_topic.original_url = link incr_counter("topics", type="link")