2016-10-06 00:42:56 +02:00
|
|
|
from argparse import ArgumentParser
|
2017-11-16 00:55:49 +01:00
|
|
|
from typing import Any
|
|
|
|
|
2024-05-24 16:49:56 +02:00
|
|
|
from django.core.management.base import CommandError
|
2023-10-12 19:43:45 +02:00
|
|
|
from typing_extensions import override
|
2016-10-06 00:42:56 +02:00
|
|
|
|
2017-01-07 03:23:44 +01:00
|
|
|
from analytics.lib.counts import do_drop_all_analytics_tables
|
2024-05-24 16:49:56 +02:00
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
2016-10-06 00:42:56 +02:00
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2024-05-24 16:49:56 +02:00
|
|
|
class Command(ZulipBaseCommand):
|
2017-01-07 03:23:44 +01:00
|
|
|
help = """Clear analytics tables."""
|
2016-10-06 00:42:56 +02:00
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
2017-11-05 06:54:00 +01:00
|
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
parser.add_argument("--force", action="store_true", help="Clear analytics tables.")
|
2016-10-06 00:42:56 +02:00
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
2017-11-05 06:54:00 +01:00
|
|
|
def handle(self, *args: Any, **options: Any) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
if options["force"]:
|
2017-01-07 03:23:44 +01:00
|
|
|
do_drop_all_analytics_tables()
|
2016-10-06 00:42:56 +02:00
|
|
|
else:
|
2021-02-12 08:19:30 +01:00
|
|
|
raise CommandError(
|
|
|
|
"Would delete all data from analytics tables (!); use --force to do so."
|
|
|
|
)
|