Skip to content

Instantly share code, notes, and snippets.

@pfurio
Last active May 17, 2017 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfurio/ace5d31a4f42750801ac4070bd830e8b to your computer and use it in GitHub Desktop.
Save pfurio/ace5d31a4f42750801ac4070bd830e8b to your computer and use it in GitHub Desktop.
Opencga 1.1.0 migration
// Use migration script https://gist.github.com/pfurio/f7cd90af08e0073699f0beeeef1958ba
/*
Migrate NUMERIC variables to DOUBLE https://github.com/opencb/opencga/issues/545
*/
// This function receives an array of variables (not variableSet),
// and will modify NUMERIC variables to DOUBLE recursively
function modifyNumeric(variables) {
var modified = false;
if (typeof variables === "undefined" || variables === null || variables.length == 0) {
return modified;
}
for (var i in variables) {
var variable = variables[i];
if (variable.type === "NUMERIC") {
variable.type = "DOUBLE";
modified = true;
} else if (typeof variable.variableSet !== "undefined") {
if (modifyNumeric(variable.variableSet)) {
modified = true;
}
}
}
return modified;
}
migrateCollection("study", {"variableSets" : { $exists: true, $ne: [] } }, {}, function(bulk, doc) {
var modified = false;
var variableSets = doc.variableSets;
for (i in variableSets) {
modified = modifyNumeric(variableSets[i].variables);
}
if (modified) {
print("Migrating variable sets from study " + doc.alias);
bulk.find({"_id": doc._id}).updateOne({"$set": {"variableSets": variableSets}});
}
});
/*
Create indexes for new family collection https://github.com/opencb/opencga/issues/582
*/
db.family.createIndex({"name": 1, "_studyId": 1}, {"unique": true});
db.family.createIndex({"mother.id": 1}, {});
db.family.createIndex({"father.id": 1}, {});
db.family.createIndex({"children.id": 1}, {});
db.family.createIndex({"acl.member": 1, "_studyId": 1}, {});
db.family.createIndex({"status.name": 1, "_studyId": 1}, {});
db.family.createIndex({"annotationSets.name": 1}, {});
db.family.createIndex({"annotationSets.variableSetId": 1}, {});
db.family.createIndex({"annotationSets.annotations.name": 1, "annotationSets.annotations.value": 1}, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment