This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
logtracker/logtracker/journal/management/commands/clean_journal.py

17 lines
552 B
Python

from django.core.management.base import BaseCommand, CommandError
from django.db import connection
class Command(BaseCommand):
help = "Remove old entries"
def add_arguments(self, parser):
parser.add_argument("--keep", type=int, default="100000")
def handle(self, *args, **options):
with connection.cursor() as cursor:
cursor.execute(
"DELETE FROM journal_entry WHERE id not in (SELECT id FROM journal_entry ORDER BY timestamp desc LIMIT %s)",
[options['keep']],
)