zulip/analytics/management/commands/clear_analytics_tables.py

26 lines
804 B
Python
Raw Normal View History

2016-10-06 00:42:56 +02:00
from argparse import ArgumentParser
2017-11-16 00:55:49 +01:00
from typing import Any
from django.core.management.base import CommandError
from typing_extensions import override
2016-10-06 00:42:56 +02:00
from analytics.lib.counts import do_drop_all_analytics_tables
from zerver.lib.management import ZulipBaseCommand
2016-10-06 00:42:56 +02:00
class Command(ZulipBaseCommand):
help = """Clear analytics tables."""
2016-10-06 00:42:56 +02:00
@override
def add_arguments(self, parser: ArgumentParser) -> None:
parser.add_argument("--force", action="store_true", help="Clear analytics tables.")
2016-10-06 00:42:56 +02:00
@override
def handle(self, *args: Any, **options: Any) -> None:
if options["force"]:
do_drop_all_analytics_tables()
2016-10-06 00:42:56 +02:00
else:
raise CommandError(
"Would delete all data from analytics tables (!); use --force to do so."
)