Skip to content

Commit

Permalink
Add upgrade script to update old concordance URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed Oct 30, 2024
1 parent 83e9823 commit 2cead9c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions utils/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,36 @@ export const upgrades = {
await annotationService.createIndexes()
console.log("... done.")
},
async "2.1.6"() {
console.log("Rewriting concordance URIs for mappings...")

// Find all concordances with "identifier" set
const concordances = await Concordance.find({
"identifier.0": { $exists: true },
})
console.log(`- Found ${concordances.length} concordances where updates might be necessary.`)

let updatedConcordaces = 0, updatedMappings = 0
for (const concordance of concordances) {
// Update concordance URIs
const result = await Mapping.updateMany({
"partOf.0.uri": {
$in: concordance.identifier,
},
}, {
"partOf.0.uri": concordance.uri,
})
if (result.modifiedCount) {
updatedConcordaces += 1
updatedMappings += result.modifiedCount
}
}
if (concordances.length) {
console.log(`- Updated ${updatedMappings} mappings in ${updatedConcordaces} concordances.`)
}

console.log("... done.")
},
}

/**
Expand Down

0 comments on commit 2cead9c

Please sign in to comment.