Browse Source

Topic: add original_url column

There are probably better ways to do this, but this should be a simple
way to start working towards some link canonicalization.
merge-requests/37/head
Deimos 6 years ago
parent
commit
d8ec29286d
  1. 30
      tildes/alembic/versions/6ede05a0ea23_topic_add_original_url_column.py
  2. 2
      tildes/tildes/models/topic/topic.py

30
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")

2
tildes/tildes/models/topic/topic.py

@ -106,6 +106,7 @@ class Topic(DatabaseModel):
_markdown: Optional[str] = deferred(Column("markdown", Text)) _markdown: Optional[str] = deferred(Column("markdown", Text))
rendered_html: Optional[str] = Column(Text) rendered_html: Optional[str] = Column(Text)
link: Optional[str] = Column(Text) link: Optional[str] = Column(Text)
original_url: Optional[str] = Column(Text)
content_metadata: Dict[str, Any] = Column( content_metadata: Dict[str, Any] = Column(
MutableDict.as_mutable(JSONB(none_as_null=True)) 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 = cls._create_base_topic(group, author, title)
new_topic.topic_type = TopicType.LINK new_topic.topic_type = TopicType.LINK
new_topic.link = link new_topic.link = link
new_topic.original_url = link
incr_counter("topics", type="link") incr_counter("topics", type="link")

Loading…
Cancel
Save