chore: update cleanup scripts to delete Home Match Player and Admin User patterns

This commit is contained in:
2026-03-31 17:02:22 -07:00
parent a82ec3c9fc
commit 8c9a8b0d9f
2 changed files with 29 additions and 36 deletions
+14 -13
View File
@@ -76,12 +76,15 @@ async function main() {
// Count test players
const testPlayerCount = countRecords('players', 'name', '%Test%') +
countRecords('players', 'name', '%Setup%') +
countRecords('players', 'name', '%Home Test%');
countRecords('players', 'name', '%Home Test%') +
countRecords('players', 'name', '%Home Match Player%') +
countRecords('players', 'name', '%Admin User%');
console.log(`Test players found: ${testPlayerCount}`);
// Count test tournaments
const testEventCount = countRecords('events', 'name', '%Test%') +
countRecords('events', 'name', '%Setup%');
countRecords('events', 'name', '%Setup%') +
countRecords('events', 'name', '%Recent%');
console.log(`Test tournaments found: ${testEventCount}`);
// Count test users
@@ -91,18 +94,18 @@ async function main() {
console.log('\n🔄 Starting cleanup...\n');
// Step 1: Delete test events (tournaments) that have no matches
console.log('1. Deleting test tournaments without matches...');
// Step 1: Delete test tournaments (with matches due to cascade delete)
console.log('1. Deleting test tournaments (matches will be deleted via cascade)...');
runSQL(
"DELETE FROM events WHERE (name LIKE '%Test%' OR name LIKE '%Setup%') AND NOT EXISTS (SELECT 1 FROM matches WHERE matches.\"eventId\" = events.id);",
"DELETE FROM events WHERE (name LIKE '%Test%' OR name LIKE '%Setup%' OR name LIKE '%Recent%');",
'Deleted test tournaments'
);
// Step 2: Delete test players that have no matches
console.log('\n2. Deleting test players without matches...');
// Step 2: Delete test players (all of them, since we deleted their matches)
console.log('\n2. Deleting test players...');
runSQL(
"DELETE FROM players WHERE (name LIKE '%Test%' OR name LIKE '%Setup%' OR name LIKE '%Home Test%') AND NOT EXISTS (SELECT 1 FROM matches WHERE matches.\"team1P1Id\" = players.id) AND NOT EXISTS (SELECT 1 FROM matches WHERE matches.\"team1P2Id\" = players.id) AND NOT EXISTS (SELECT 1 FROM matches WHERE matches.\"team2P1Id\" = players.id) AND NOT EXISTS (SELECT 1 FROM matches WHERE matches.\"team2P2Id\" = players.id);",
'Deleted test players without matches'
"DELETE FROM players WHERE (name LIKE '%Test%' OR name LIKE '%Setup%' OR name LIKE '%Home Test%' OR name LIKE '%Home Match Player%' OR name LIKE '%Admin User%');",
'Deleted test players'
);
// Step 3: Delete test users (they shouldn't have player associations)
@@ -119,10 +122,8 @@ async function main() {
runSQL("SELECT COUNT(*) FROM events WHERE name LIKE '%Test%' OR name LIKE '%Setup%';", 'Remaining test tournaments');
runSQL("SELECT COUNT(*) FROM users WHERE email LIKE '%test%' OR email LIKE '%setup%';", 'Remaining test users');
console.log('\n💡 Note: Some test records may remain if they have:');
console.log(' - Associated matches');
console.log(' - Associated users');
console.log(' These were preserved to maintain data integrity.');
console.log('\n💡 Note: All test records deleted. Matches are automatically deleted');
console.log(' via cascade delete when their parent tournament is deleted.');
});
}