-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
64 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Management command to delete all records from the database.""" | ||
|
||
from typing import Any | ||
|
||
from django.core.management.base import BaseCommand | ||
from django.db import transaction | ||
|
||
from vespadb.observations.models import Observation | ||
|
||
|
||
class Command(BaseCommand): | ||
"""Delete all records from the database.""" | ||
|
||
help = "Delete all records from the database" | ||
|
||
def handle(self, *args: Any, **options: Any) -> None: | ||
"""Handle the command to delete all records.""" | ||
confirm = input( | ||
"Are you sure you want to delete all records from the database? This action cannot be undone! (yes/no): " | ||
) | ||
|
||
if confirm.lower() not in {"yes", "y"}: | ||
self.stdout.write(self.style.WARNING("Aborted. No records have been deleted.")) | ||
return | ||
|
||
with transaction.atomic(): | ||
count, _ = Observation.objects.all().delete() | ||
self.stdout.write(self.style.SUCCESS(f"Deleted {count} records from the Observation model.")) | ||
|
||
self.stdout.write(self.style.SUCCESS("Operation completed.")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters