-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmongoose.js
More file actions
42 lines (37 loc) · 1.02 KB
/
Copy pathmongoose.js
File metadata and controls
42 lines (37 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* Author : Anuj Jamwal
* Date : May 11, 2012
* file : mongoose.js
*
*/
var migrations = new Array();
function isJsFile(file) {
return ((!file.isDirectory) && (file.name.lastIndexOf(".js") == (file.name.length-3)));
}
function notAlreadyExecuted(migration) {
return (db.Mongoose.find({"_id":migration}).count() <= 0);
};
print("Reading Migrations ...");
listFiles("migrations").forEach(function(file) {
if(isJsFile(file)) {
migrations[parseInt(file.name.match(/[1-9][0-9]*/)[0])] = file.name;
}
});
print((migrations.length-1)+ " Migration scripts found ...");
print("Executing Migrations ...");
migrations.forEach(function(file) {
if(notAlreadyExecuted(file)) {
try {
load(file);
} catch (error) {
print("error occured executing..." + file);
print("Aborting Mongoose....");
quit();
}
print(file+" : Successfully executed ..." );
db.Mongoose.save({"_id":file, "runTime":new Date()});
print("Marked Executed.....");
} else {
print(file+" is Already Executed. Skipping ... ");
}
});