From c3c9bb9952f6f4d4d3c7c894355b323f50726320 Mon Sep 17 00:00:00 2001 From: mk2155 <mk2155@cam.ac.uk> Date: Mon, 11 Nov 2024 15:03:39 +0000 Subject: [PATCH] feat: add management command to delete accounts This is needed to support development and staging activities, so that we can remove and re-populate test data for use in user acceptance testing. --- .../commands/delete_all_account_data.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 activate_account/management/commands/delete_all_account_data.py diff --git a/activate_account/management/commands/delete_all_account_data.py b/activate_account/management/commands/delete_all_account_data.py new file mode 100644 index 0000000..15c2899 --- /dev/null +++ b/activate_account/management/commands/delete_all_account_data.py @@ -0,0 +1,25 @@ +from pprint import pprint + +from django.core.management.base import BaseCommand + +from activate_account.models import Account + + +class Command(BaseCommand): + help = "Deletes account data in databases" + + def handle(self, *args, **options): + account_count = Account.objects.all().count() + if account_count == 0: + self.stdout.write(self.style.SUCCESS("No accounts to delete.")) + return + + self.stdout.write(self.style.WARNING("Deleting account data in database...")) + self.stdout.write(f"There are currently {account_count} accounts in the database.") + self.stdout.write(self.style.WARNING("Are you sure you want to continue?")) + + result = input("Enter 'yes' to delete all data: ") + if result.lower() == "yes": + pprint(Account.objects.all().delete()) + else: + self.stdout.write("Not deleting any objects.") -- GitLab