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
+15 -23
View File
@@ -40,12 +40,15 @@ console.log('=============================================\n');
// 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
@@ -57,7 +60,7 @@ console.log(`Test users found: ${testUserCount}`);
runSQL(`
SELECT id, name
FROM players
WHERE name LIKE '%Test%' OR name LIKE '%Setup%' OR name LIKE '%Home Test%'
WHERE name LIKE '%Test%' OR name LIKE '%Setup%' OR name LIKE '%Home Test%' OR name LIKE '%Home Match Player%' OR name LIKE '%Admin User%'
ORDER BY name;
`, 'Test players list');
@@ -65,7 +68,7 @@ runSQL(`
runSQL(`
SELECT id, name
FROM events
WHERE name LIKE '%Test%' OR name LIKE '%Setup%'
WHERE name LIKE '%Test%' OR name LIKE '%Setup%' OR name LIKE '%Recent%'
ORDER BY name;
`, 'Test events list');
@@ -77,35 +80,24 @@ runSQL(`
ORDER BY email;
`, 'Test users list');
// Check which test players have matches
// Check which test players have matches (simplified query)
runSQL(`
SELECT p.id, p.name
FROM players p
WHERE (p.name LIKE '%Test%' OR p.name LIKE '%Setup%' OR p.name LIKE '%Home Test%')
AND EXISTS (
SELECT 1 FROM matches m
WHERE m."team1P1Id" = p.id
OR m."team1P2Id" = p.id
OR m."team2P1Id" = p.id
OR m."team2P2Id" = p.id
)
WHERE (p.name LIKE '%Test%' OR p.name LIKE '%Setup%' OR p.name LIKE '%Home Test%' OR p.name LIKE '%Home Match Player%' OR p.name LIKE '%Admin User%')
ORDER BY p.name;
`, 'Test players with matches (will be preserved)');
`, 'Test players (will be deleted)');
// Check which test events have matches
// Check which test events exist
runSQL(`
SELECT e.id, e.name
FROM events e
WHERE (e.name LIKE '%Test%' OR e.name LIKE '%Setup%')
AND EXISTS (
SELECT 1 FROM matches m WHERE m."eventId" = e.id
)
WHERE (e.name LIKE '%Test%' OR e.name LIKE '%Setup%' OR e.name LIKE '%Recent%')
ORDER BY e.name;
`, 'Test events with matches (will be preserved)');
`, 'Test events (will be deleted with matches via cascade)');
console.log('\n✅ Check complete!');
console.log('\n💡 Summary:');
console.log(' - Test players without matches can be deleted');
console.log(' - Test tournaments without matches can be deleted');
console.log(' - Test tournaments (with matches) can be deleted');
console.log(' - Test players can be deleted');
console.log(' - Test users without player associations can be deleted');
console.log(' - Records with matches/associations are preserved');
+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.');
});
}