mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-24 03:30:50 +02:00
updates
This commit is contained in:
parent
ffbda787ae
commit
98d8e4ec93
2 changed files with 7 additions and 8 deletions
|
@ -64,15 +64,18 @@ class Command(BaseCommand):
|
||||||
model = apps.get_model("registrar", table_name)
|
model = apps.get_model("registrar", table_name)
|
||||||
BATCH_SIZE = 1000
|
BATCH_SIZE = 1000
|
||||||
total_deleted = 0
|
total_deleted = 0
|
||||||
while True:
|
|
||||||
pks = list(model.objects.values_list("pk", flat=True)[:BATCH_SIZE])
|
# Get initial batch of primary keys
|
||||||
if not pks:
|
pks = list(model.objects.values_list("pk", flat=True)[:BATCH_SIZE])
|
||||||
break
|
|
||||||
|
while pks:
|
||||||
# Use a transaction to ensure database integrity
|
# Use a transaction to ensure database integrity
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
deleted, _ = model.objects.filter(pk__in=pks).delete()
|
deleted, _ = model.objects.filter(pk__in=pks).delete()
|
||||||
total_deleted += deleted
|
total_deleted += deleted
|
||||||
logger.debug(f"Deleted {deleted} {table_name}s, total deleted: {total_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")
|
logger.info(f"Successfully cleaned table {table_name}, deleted {total_deleted} rows")
|
||||||
except LookupError:
|
except LookupError:
|
||||||
logger.error(f"Model for table {table_name} not found.")
|
logger.error(f"Model for table {table_name} not found.")
|
||||||
|
|
|
@ -33,10 +33,6 @@ from api.tests.common import less_console_noise_decorator
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CustomDeleteException(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class TestPopulateVerificationType(MockEppLib):
|
class TestPopulateVerificationType(MockEppLib):
|
||||||
"""Tests for the populate_organization_type script"""
|
"""Tests for the populate_organization_type script"""
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue