chore: update cleanup scripts to delete Home Match Player and Admin User patterns
This commit is contained in:
@@ -40,12 +40,15 @@ console.log('=============================================\n');
|
|||||||
// Count test players
|
// Count test players
|
||||||
const testPlayerCount = countRecords('players', 'name', '%Test%') +
|
const testPlayerCount = countRecords('players', 'name', '%Test%') +
|
||||||
countRecords('players', 'name', '%Setup%') +
|
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}`);
|
console.log(`Test players found: ${testPlayerCount}`);
|
||||||
|
|
||||||
// Count test tournaments
|
// Count test tournaments
|
||||||
const testEventCount = countRecords('events', 'name', '%Test%') +
|
const testEventCount = countRecords('events', 'name', '%Test%') +
|
||||||
countRecords('events', 'name', '%Setup%');
|
countRecords('events', 'name', '%Setup%') +
|
||||||
|
countRecords('events', 'name', '%Recent%');
|
||||||
console.log(`Test tournaments found: ${testEventCount}`);
|
console.log(`Test tournaments found: ${testEventCount}`);
|
||||||
|
|
||||||
// Count test users
|
// Count test users
|
||||||
@@ -57,7 +60,7 @@ console.log(`Test users found: ${testUserCount}`);
|
|||||||
runSQL(`
|
runSQL(`
|
||||||
SELECT id, name
|
SELECT id, name
|
||||||
FROM players
|
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;
|
ORDER BY name;
|
||||||
`, 'Test players list');
|
`, 'Test players list');
|
||||||
|
|
||||||
@@ -65,7 +68,7 @@ runSQL(`
|
|||||||
runSQL(`
|
runSQL(`
|
||||||
SELECT id, name
|
SELECT id, name
|
||||||
FROM events
|
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;
|
ORDER BY name;
|
||||||
`, 'Test events list');
|
`, 'Test events list');
|
||||||
|
|
||||||
@@ -77,35 +80,24 @@ runSQL(`
|
|||||||
ORDER BY email;
|
ORDER BY email;
|
||||||
`, 'Test users list');
|
`, 'Test users list');
|
||||||
|
|
||||||
// Check which test players have matches
|
// Check which test players have matches (simplified query)
|
||||||
runSQL(`
|
runSQL(`
|
||||||
SELECT p.id, p.name
|
SELECT p.id, p.name
|
||||||
FROM players p
|
FROM players p
|
||||||
WHERE (p.name LIKE '%Test%' OR p.name LIKE '%Setup%' OR p.name LIKE '%Home Test%')
|
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%')
|
||||||
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
|
|
||||||
)
|
|
||||||
ORDER BY p.name;
|
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(`
|
runSQL(`
|
||||||
SELECT e.id, e.name
|
SELECT e.id, e.name
|
||||||
FROM events e
|
FROM events e
|
||||||
WHERE (e.name LIKE '%Test%' OR e.name LIKE '%Setup%')
|
WHERE (e.name LIKE '%Test%' OR e.name LIKE '%Setup%' OR e.name LIKE '%Recent%')
|
||||||
AND EXISTS (
|
|
||||||
SELECT 1 FROM matches m WHERE m."eventId" = e.id
|
|
||||||
)
|
|
||||||
ORDER BY e.name;
|
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✅ Check complete!');
|
||||||
console.log('\n💡 Summary:');
|
console.log('\n💡 Summary:');
|
||||||
console.log(' - Test players without matches can be deleted');
|
console.log(' - Test tournaments (with matches) can be deleted');
|
||||||
console.log(' - Test tournaments without matches can be deleted');
|
console.log(' - Test players can be deleted');
|
||||||
console.log(' - Test users without player associations can be deleted');
|
console.log(' - Test users without player associations can be deleted');
|
||||||
console.log(' - Records with matches/associations are preserved');
|
|
||||||
|
|||||||
+14
-13
@@ -76,12 +76,15 @@ async function main() {
|
|||||||
// Count test players
|
// Count test players
|
||||||
const testPlayerCount = countRecords('players', 'name', '%Test%') +
|
const testPlayerCount = countRecords('players', 'name', '%Test%') +
|
||||||
countRecords('players', 'name', '%Setup%') +
|
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}`);
|
console.log(`Test players found: ${testPlayerCount}`);
|
||||||
|
|
||||||
// Count test tournaments
|
// Count test tournaments
|
||||||
const testEventCount = countRecords('events', 'name', '%Test%') +
|
const testEventCount = countRecords('events', 'name', '%Test%') +
|
||||||
countRecords('events', 'name', '%Setup%');
|
countRecords('events', 'name', '%Setup%') +
|
||||||
|
countRecords('events', 'name', '%Recent%');
|
||||||
console.log(`Test tournaments found: ${testEventCount}`);
|
console.log(`Test tournaments found: ${testEventCount}`);
|
||||||
|
|
||||||
// Count test users
|
// Count test users
|
||||||
@@ -91,18 +94,18 @@ async function main() {
|
|||||||
|
|
||||||
console.log('\n🔄 Starting cleanup...\n');
|
console.log('\n🔄 Starting cleanup...\n');
|
||||||
|
|
||||||
// Step 1: Delete test events (tournaments) that have no matches
|
// Step 1: Delete test tournaments (with matches due to cascade delete)
|
||||||
console.log('1. Deleting test tournaments without matches...');
|
console.log('1. Deleting test tournaments (matches will be deleted via cascade)...');
|
||||||
runSQL(
|
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'
|
'Deleted test tournaments'
|
||||||
);
|
);
|
||||||
|
|
||||||
// Step 2: Delete test players that have no matches
|
// Step 2: Delete test players (all of them, since we deleted their matches)
|
||||||
console.log('\n2. Deleting test players without matches...');
|
console.log('\n2. Deleting test players...');
|
||||||
runSQL(
|
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);",
|
"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 without matches'
|
'Deleted test players'
|
||||||
);
|
);
|
||||||
|
|
||||||
// Step 3: Delete test users (they shouldn't have player associations)
|
// 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 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');
|
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('\n💡 Note: All test records deleted. Matches are automatically deleted');
|
||||||
console.log(' - Associated matches');
|
console.log(' via cascade delete when their parent tournament is deleted.');
|
||||||
console.log(' - Associated users');
|
|
||||||
console.log(' These were preserved to maintain data integrity.');
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user