refactor: delete all backup files, not just the latest

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-22 12:51:05 +08:00
parent 8c70e8681b
commit 892d0b40e1

View File

@@ -74,24 +74,27 @@ def delete(ctx):
if not backup_files:
click.echo("No backup files found in ./backups")
raise SystemExit(1)
csv_file = backup_files[-1]
import csv as csv_mod
with open(csv_file, newline="") as f:
count = sum(1 for _ in csv_mod.DictReader(f))
total = 0
for f in backup_files:
with open(f, newline="") as fh:
total += sum(1 for _ in csv_mod.DictReader(fh))
click.echo(f" {f}")
click.echo(f"Will delete {count} orders from {csv_file}")
click.echo(f"Will delete {total} orders from {len(backup_files)} file(s)")
if not click.confirm("Continue?"):
click.echo("Aborted")
return
table = TableClient.from_connection_string(cfg.azure_connection_string, table_name="order")
delete_orders(
table_client=table,
csv_path=csv_file,
batch_size=cfg.delete_batch_size,
delay_ms=cfg.delete_delay_ms,
)
for csv_file in backup_files:
delete_orders(
table_client=table,
csv_path=csv_file,
batch_size=cfg.delete_batch_size,
delay_ms=cfg.delete_delay_ms,
)
if __name__ == "__main__":