analytics: Add lib/ function to drop all analytics tables.

This commit is contained in:
Rishi Gupta
2017-01-06 18:23:44 -08:00
committed by Tim Abbott
parent 73dc904e9c
commit f5899dd14b
2 changed files with 13 additions and 13 deletions

View File

@@ -115,6 +115,14 @@ def do_delete_count_stat_at_hour(stat, end_time):
RealmCount.objects.filter(property = stat.property, end_time = end_time).delete()
InstallationCount.objects.filter(property = stat.property, end_time = end_time).delete()
def do_drop_all_analytics_tables():
# type: () -> None
UserCount.objects.all().delete()
StreamCount.objects.all().delete()
RealmCount.objects.all().delete()
InstallationCount.objects.all().delete()
FillState.objects.all().delete()
def do_aggregate_to_summary_table(stat, end_time, interval):
# type: (CountStat, datetime, str) -> None
cursor = connection.cursor()

View File

@@ -7,31 +7,23 @@ from argparse import ArgumentParser
from django.db import connection
from django.core.management.base import BaseCommand
from analytics.lib.counts import do_drop_all_analytics_tables
from typing import Any
CLEAR_QUERY = """
DELETE FROM ONLY analytics_installationcount;
DELETE FROM ONLY analytics_realmcount;
DELETE FROM ONLY analytics_usercount;
DELETE FROM ONLY analytics_streamcount;
DELETE FROM ONLY analytics_fillstate;
"""
class Command(BaseCommand):
help = """Clear Analytics tables."""
help = """Clear analytics tables."""
def add_arguments(self, parser):
# type: (ArgumentParser) -> None
parser.add_argument('--force',
action='store_true',
help="Clear analytics Tables.")
help="Clear analytics tables.")
def handle(self, *args, **options):
# type: (*Any, **Any) -> None
if options['force']:
cursor = connection.cursor()
cursor.execute(CLEAR_QUERY)
cursor.close()
do_drop_all_analytics_tables()
else:
print("Would delete all data from analytics tables (!); use --force to do so.")
sys.exit(1)