Add script to clear analytics tables.

This commit is contained in:
umkay 2016-10-05 15:42:56 -07:00 committed by Tim Abbott
parent 777fcaa6a0
commit 5d0bed8673
1 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,38 @@
from __future__ import absolute_import
from __future__ import print_function
import sys
from argparse import ArgumentParser
from django.db import connection
from django.core.management.base import BaseCommand
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_huddlecount
"""
class Command(BaseCommand):
help = """Clear Analytics tables."""
def add_arguments(self, parser):
# type: (ArgumentParser) -> None
parser.add_argument('--force',
action='store_true',
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()
else:
print("Would delete all data from analytics tables (!); use --force to do so.")
sys.exit(1)