From 17024f91a82e6e79c6006282d7b931b933c054e3 Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Sat, 18 Apr 2026 14:43:56 +0200 Subject: [PATCH] fix/dev: fix devscripts for platform --- dev/scripts/setup-db.js | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/dev/scripts/setup-db.js b/dev/scripts/setup-db.js index c8bcf68..de3bd86 100644 --- a/dev/scripts/setup-db.js +++ b/dev/scripts/setup-db.js @@ -42,7 +42,7 @@ async function setupDatabase() { // Check for platform-specific match files let foundPlatformFiles = []; for (const platform of platforms) { - const platformFile = `${latestPatch}_${platform}_matches.json`; + const platformFile = `${latestPatch}_${platform}.json`; const fullPath = path.join(dataDir, platformFile); if (fs.existsSync(fullPath)) { foundPlatformFiles.push(platform); @@ -323,9 +323,15 @@ async function importMatchesData(patchVersion, foundPlatformFiles = []) { // If platform-specific files were found, import each one if (foundPlatformFiles.length > 0) { for (const platform of foundPlatformFiles) { - const matchesFile = path.join(dataDir, `${patchVersion}_${platform}_matches.json`); + // Try both formats: patch_PLATFORM.json and patch_PLATFORM_matches.json + let matchesFile = path.join(dataDir, `${patchVersion}_${platform}.json`); const collectionName = `${patchVersion}_${platform}`; + // Fallback to _matches.json suffix if the direct file doesn't exist + if (!fs.existsSync(matchesFile)) { + matchesFile = path.join(dataDir, `${patchVersion}_${platform}_matches.json`); + } + if (fs.existsSync(matchesFile)) { console.log(`📥 Importing matches for ${platform}...`); execSync( @@ -336,21 +342,32 @@ async function importMatchesData(patchVersion, foundPlatformFiles = []) { } ); console.log(`✅ Matches import completed for ${platform}`); + } else { + console.log(`⚠️ No match file found for ${platform}`); } } } else { // Fall back to old format (single file without platform suffix) - const matchesFile = path.join(dataDir, `${patchVersion}_matches.json`); + // Try both formats: patch_matches.json and patch.json + let matchesFile = path.join(dataDir, `${patchVersion}_matches.json`); const collectionName = patchVersion; - execSync( - `node ${path.join(__dirname, 'process-matches.js')} ${matchesFile} ${collectionName} 1000`, - { - stdio: 'inherit', - env: { ...process.env, MONGO_URI: getMongoUri() } - } - ); - console.log('✅ Matches import completed'); + if (!fs.existsSync(matchesFile)) { + matchesFile = path.join(dataDir, `${patchVersion}.json`); + } + + if (fs.existsSync(matchesFile)) { + execSync( + `node ${path.join(__dirname, 'process-matches.js')} ${matchesFile} ${collectionName} 1000`, + { + stdio: 'inherit', + env: { ...process.env, MONGO_URI: getMongoUri() } + } + ); + console.log('✅ Matches import completed'); + } else { + console.log(`⚠️ No match file found for patch ${patchVersion}`); + } } } catch (error) { console.error('❌ Failed to import matches:', error);