mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	analytics: Add lib/ function to drop all analytics tables.
This commit is contained in:
		@@ -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()
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user