This commit is contained in:
David Kennedy 2024-07-30 22:10:05 -04:00
parent ffbda787ae
commit 98d8e4ec93
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
2 changed files with 7 additions and 8 deletions

View file

@ -64,15 +64,18 @@ class Command(BaseCommand):
model = apps.get_model("registrar", table_name)
BATCH_SIZE = 1000
total_deleted = 0
while True:
pks = list(model.objects.values_list("pk", flat=True)[:BATCH_SIZE])
if not pks:
break
# Get initial batch of primary keys
pks = list(model.objects.values_list("pk", flat=True)[:BATCH_SIZE])
while pks:
# Use a transaction to ensure database integrity
with transaction.atomic():
deleted, _ = model.objects.filter(pk__in=pks).delete()
total_deleted += deleted
logger.debug(f"Deleted {deleted} {table_name}s, total deleted: {total_deleted}")
# Get the next batch of primary keys
pks = list(model.objects.values_list("pk", flat=True)[:BATCH_SIZE])
logger.info(f"Successfully cleaned table {table_name}, deleted {total_deleted} rows")
except LookupError:
logger.error(f"Model for table {table_name} not found.")

View file

@ -33,10 +33,6 @@ from api.tests.common import less_console_noise_decorator
logger = logging.getLogger(__name__)
class CustomDeleteException(Exception):
pass
class TestPopulateVerificationType(MockEppLib):
"""Tests for the populate_organization_type script"""