Add emergency cleanup button

This commit is contained in:
gpt-engineer-app[bot]
2025-10-30 15:18:29 +00:00
parent 1874b6ffbd
commit 41ae88d1bc

View File

@@ -14,6 +14,7 @@ import { useToast } from '@/hooks/use-toast';
import { getErrorMessage } from '@/lib/errorHandler';
import { Beaker, CheckCircle, ChevronDown, Trash2, AlertTriangle } from 'lucide-react';
import { clearTestData, getTestDataStats } from '@/lib/testDataGenerator';
import { TestDataTracker } from '@/lib/integrationTests/TestDataTracker';
import { logger } from '@/lib/logger';
const PRESETS = {
@@ -186,6 +187,29 @@ export function TestDataGenerator(): React.JSX.Element {
}
};
const handleEmergencyCleanup = async (): Promise<void> => {
setLoading(true);
try {
const { deleted, errors } = await TestDataTracker.bulkCleanupAllTestData();
await loadStats();
toast({
title: 'Emergency Cleanup Complete',
description: `Deleted ${deleted} test records across all tables${errors > 0 ? `, ${errors} errors` : ''}`
});
setResults(null);
} catch (error: unknown) {
toast({
title: 'Emergency Cleanup Failed',
description: getErrorMessage(error),
variant: 'destructive'
});
} finally {
setLoading(false);
}
};
return (
<Card>
<CardHeader>
@@ -417,6 +441,38 @@ export function TestDataGenerator(): React.JSX.Element {
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
<AlertDialog>
<AlertDialogTrigger asChild>
<Button variant="outline" disabled={loading} className="border-destructive text-destructive hover:bg-destructive/10">
<AlertTriangle className="w-4 h-4 mr-2" />
Emergency Cleanup (All Tables)
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Emergency Cleanup - Delete ALL Test Data?</AlertDialogTitle>
<AlertDialogDescription className="space-y-2">
<p className="font-medium text-destructive"> This is a nuclear option!</p>
<p>This will delete ALL records marked with is_test_data: true from ALL entity tables, including:</p>
<ul className="list-disc list-inside text-sm space-y-1">
<li>Parks, Rides, Companies (operators, manufacturers, etc.)</li>
<li>Ride Models, Photos, Reviews</li>
<li>Entity Versions, Edit History</li>
<li>Moderation Queue submissions</li>
</ul>
<p className="font-medium">This goes far beyond the moderation queue and cannot be undone.</p>
<p className="text-sm">Only use this if normal cleanup fails or you need to completely reset test data.</p>
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction onClick={handleEmergencyCleanup} className="bg-destructive text-destructive-foreground hover:bg-destructive/90">
Delete All Test Data
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
</CardContent>
</Card>