Browse Source

Clean private data script: use default values

No functional difference, but probably a little better to use default
values where possible instead of specifying particular ways of setting
it back to default (especially for things like topic_type).
merge-requests/53/head
Deimos 6 years ago
parent
commit
d4bd091173
  1. 22
      tildes/scripts/clean_private_data.py

22
tildes/scripts/clean_private_data.py

@ -13,6 +13,7 @@ from datetime import datetime, timedelta
import logging import logging
from sqlalchemy.orm.session import Session from sqlalchemy.orm.session import Session
from sqlalchemy.sql.expression import text
from tildes.lib.database import get_session_from_config from tildes.lib.database import get_session_from_config
from tildes.models.comment import Comment from tildes.models.comment import Comment
@ -23,6 +24,9 @@ from tildes.models.topic import Topic, TopicVisit
# sensitive data older than this should be removed # sensitive data older than this should be removed
RETENTION_PERIOD = timedelta(days=30) RETENTION_PERIOD = timedelta(days=30)
# used to set a column back to its default value
DEFAULT = text("DEFAULT")
def clean_all_data(config_path: str) -> None: def clean_all_data(config_path: str) -> None:
"""Clean all private/deleted data. """Clean all private/deleted data.
@ -94,7 +98,7 @@ class DataCleaner:
.update( .update(
{ {
"user_id": 0, "user_id": 0,
"last_edited_time": None,
"last_edited_time": DEFAULT,
"markdown": "", "markdown": "",
"rendered_html": "", "rendered_html": "",
"excerpt": "", "excerpt": "",
@ -121,15 +125,15 @@ class DataCleaner:
.update( .update(
{ {
"user_id": 0, "user_id": 0,
"last_edited_time": None,
"last_edited_time": DEFAULT,
"title": "", "title": "",
"topic_type": "TEXT",
"markdown": None,
"rendered_html": None,
"link": None,
"original_url": None,
"content_metadata": None,
"_tags": [],
"topic_type": DEFAULT,
"markdown": DEFAULT,
"rendered_html": DEFAULT,
"link": DEFAULT,
"original_url": DEFAULT,
"content_metadata": DEFAULT,
"_tags": DEFAULT,
}, },
synchronize_session=False, synchronize_session=False,
) )

Loading…
Cancel
Save