Created
September 23, 2021 06:33
-
-
Save inlightmedia/3cbf08918f3c4bcd474be73a9b5991ec to your computer and use it in GitHub Desktop.
Finding duplicate relations in prisma1 export data.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const numberOfRelationJSONFiles = 131; // NOTE: Change this to the number of json files in the relation folder | |
for (let i=1; i <= numberOfRelationJSONFiles; i++ ) { | |
let filename = ``; | |
if (i < 10) { | |
filename = `00000${i}` | |
} | |
if (i < 100 && i > 9) { | |
filename = `0000${i}` | |
} | |
if (i >= 100) { | |
filename = `000${i}` | |
} | |
const relationJSON = require(`./relations/${filename}.json`); | |
const allRelationAIDs = []; | |
const duplicateRelationAIds = []; | |
relationJSON.values.forEach(relation => { | |
const [relationA, relationB] = relation; | |
if (allRelationAIDs.includes(`${relationA.id} ${relationB.id}`)) { | |
duplicateRelationAIds.push(`${relationA.id} ${relationB.id}`); | |
} | |
allRelationAIDs.push(`${relationA.id} ${relationB.id}`); | |
}) | |
duplicateRelationAIds.length > 0 && console.log(`DUPLICATES FOUND IN (${filename}.json): \n`, duplicateRelationAIds); | |
duplicateRelationAIds.length === 0 && console.log('Scanning files for duplicates...'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment