Skip to content

Commit

Permalink
Fixed mongo migrate script for dataset unified schema
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrosx committed Sep 20, 2024
1 parent a3b02f9 commit c5e1040
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions migrations/20240920111733-dataset-unified-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,44 @@ module.exports = {
// See https://github.com/seppevs/migrate-mongo/#creating-a-new-migration-script
// Example:
// await db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: true}});
await db.collection("Dataset").updateMany(
{},
await db.collection("Dataset").updateMany({}, [
{
$set: {
proposalIds: "$proposalId",
instrumentIds: "$instrumentId",
sampleIds: "$sampleId",
proposalIds: ["$proposalId"],
instrumentIds: ["$instrumentId"],
sampleIds: ["$sampleId"],
},
},
);
await db.collection("Dataset").updateMany(
{ type: "derived" },
]);
await db.collection("Dataset").updateMany({ type: "derived" }, [
{
$set: {
principalInvestigator: "$investigator",
},
},
);
]);
},

async down(db, client) {
// TODO write the statements to rollback your migration (if possible)
// Example:
// await db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: false}});

await db.collection("Dataset").updateMany(
{},
await db.collection("Dataset").updateMany({}, [
{
$set: {
proposalId: "$proposalIds[0]",
instrumentId: "$instrumentId[0]",
sampleId: "$sampleId[0]",
},
},
);
await db.collection("Dataset").updateMany(
{ type: "derived" },
]);
await db.collection("Dataset").updateMany({ type: "derived" }, [
{
$set: {
investigator: "$principalInvestigator",
},
},
);
]);
},
};

0 comments on commit c5e1040

Please sign in to comment.