-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Florin H
committed
Oct 30, 2023
1 parent
452a70f
commit 2d4bc11
Showing
12 changed files
with
1,400 additions
and
105 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import * as client from '../src/lib/client'; | ||
import * as helpers from '../src/lib/helpers'; | ||
import * as publicationVersionService from '../src/components/publicationVersion/service'; | ||
|
||
const createVersionedDOIs = async (): Promise<number> => { | ||
// get the latest LIVE version of each publication | ||
const latestLiveVersions = await client.prisma.publicationVersion.findMany({ | ||
where: { | ||
isLatestLiveVersion: true, | ||
createdBy: { | ||
not: 'octopus' // ignore seed data publications | ||
}, | ||
doi: null // only get versions without DOI | ||
}, | ||
include: { | ||
publication: { | ||
select: { | ||
id: true, | ||
type: true, | ||
doi: true, | ||
topics: true, | ||
publicationFlags: true, | ||
url_slug: true | ||
} | ||
}, | ||
publicationStatus: { | ||
select: { | ||
status: true, | ||
createdAt: true, | ||
id: true | ||
}, | ||
orderBy: { | ||
createdAt: 'desc' | ||
} | ||
}, | ||
funders: { | ||
select: { | ||
id: true, | ||
city: true, | ||
country: true, | ||
name: true, | ||
link: true, | ||
ror: true | ||
} | ||
}, | ||
coAuthors: { | ||
select: { | ||
id: true, | ||
email: true, | ||
linkedUser: true, | ||
publicationVersionId: true, | ||
confirmedCoAuthor: true, | ||
approvalRequested: true, | ||
createdAt: true, | ||
reminderDate: true, | ||
isIndependent: true, | ||
affiliations: true, | ||
user: { | ||
select: { | ||
firstName: true, | ||
lastName: true, | ||
orcid: true | ||
} | ||
} | ||
}, | ||
orderBy: { | ||
position: 'asc' | ||
} | ||
}, | ||
user: { | ||
select: { | ||
id: true, | ||
orcid: true, | ||
firstName: true, | ||
lastName: true, | ||
email: true, | ||
createdAt: true, | ||
updatedAt: true | ||
} | ||
} | ||
} | ||
}); | ||
|
||
console.log(`Found ${latestLiveVersions.length} without a DOI.`); | ||
|
||
let createdVersionDOIsCount = 0; | ||
|
||
for (const version of latestLiveVersions) { | ||
// create a new DOI for each version | ||
console.log(`Creating version ${version.versionNumber} DOI for publication ${version.versionOf}`); | ||
const versionDOIResponse = await helpers.createPublicationVersionDOI(version); | ||
const versionDOI = versionDOIResponse.data.attributes.doi; | ||
|
||
console.log(`Successfully created version ${version.versionNumber} DOI: ${versionDOI}`); | ||
|
||
// update publication "HasVersion" with the created DOI | ||
console.log(`Updating canonical DOI: ${version.publication.doi} "HasVersion" with version DOI: ${versionDOI}`); | ||
await helpers.updatePublicationDOI(version.publication.doi, version); | ||
|
||
console.log(`Successfully updated canonical DOI: ${version.publication.doi}`); | ||
|
||
// update version DOI | ||
console.log(`Updating version DOI: ${versionDOI} in DB`); | ||
|
||
await publicationVersionService.update(version.id, { | ||
doi: versionDOI | ||
}); | ||
|
||
createdVersionDOIsCount += 1; | ||
console.log(); // new line | ||
} | ||
|
||
return createdVersionDOIsCount; | ||
}; | ||
|
||
createVersionedDOIs() | ||
.then((versionedDOIsCount) => | ||
console.log(`Successfully created ${versionedDOIsCount} versioned DOIs and updated their canonical DOIs`) | ||
) | ||
.catch((err) => console.log(err)); |
2 changes: 2 additions & 0 deletions
2
api/prisma/migrations/20231026083835_added_version_doi/migration.sql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "PublicationVersion" ADD COLUMN "doi" TEXT; |
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
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
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
Oops, something went wrong.