-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy path20190828172432-populateProjectLegislation.js
135 lines (125 loc) · 2.57 KB
/
20190828172432-populateProjectLegislation.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
'use strict';
var dbm;
var type;
var seed;
/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
};
exports.up = function(db) {
let mClient;
return db.connection.connect(db.connectionString, { native_parser: true })
.then((mClientInst) => {
// mClientInst is an instance of MongoClient
mClient = mClientInst;
var p = mClient.collection('epic');
// these are the projects that are under the 1996 legislation.
// At this time all other projects were under the 2002 legislation.
// NOTE: epicProjectId is depreciated now
const epicProjectIds1996Legislation = [
45,
129,
152,
84,
140,
132,
21,
77,
145,
78,
85,
9,
52,
16,
34,
8,
79,
31,
80,
86,
41,
82,
81,
10,
3,
22,
27,
42,
141,
57,
65,
23,
139,
30,
46,
56,
7,
146,
127,
48,
64,
186,
12,
37,
62,
4,
184,
47,
54,
29,
188,
51,
39,
36,
35,
68,
33,
72,
5,
44,
40,
13,
26
];
let projectLegislation = '';
p.aggregate([
{
$match: { _schemaName: "Project" }
}
])
.toArray()
.then(function (arr) {
for (let item of arr) {
projectLegislation = '2002 Environmental Assessment Act';
for (let epicProjId of epicProjectIds1996Legislation){
if (item.epicProjectID === epicProjId){
projectLegislation = '1996 Environmental Assessment Act';
break;
}
}
p.update(
{
_id: item._id
},
{
$set: { legislation: projectLegislation }
});
}
mClient.close();
});
})
.catch((e) => {
console.log("e:", e);
mClient.close()
});};
exports.down = function(db) {
return null;
};
exports._meta = {
"version": 1
};