-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMigration.js
74 lines (56 loc) · 2.07 KB
/
Migration.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
// const mongoose = require('mongoose');
// const Schema = mongoose.Schema;
// const User = require('./User');
//* Using migrate-mongo
module.exports = {
async up(db, client) {
const cursor = await db.collection('User').find();
while (await cursor.hasNext()) {
const doc = await cursor.next();
const version = 1;
await db.collection('User').updateOne({_id: doc._id}, {$set: {version: version}});
}
},
async down(db, client) {
await db.collection('User').updateMany({}, {$unset: {version: true}});
},
};
module.exports = {
async up(db, client) {
const cursor = await db.collection('User').find();
while (await cursor.hasNext()) {
const doc = await cursor.next();
const isEmailVerified = false;
await db.collection('User').updateOne({_id: doc._id}, {$set: {isEmailVerified: isEmailVerified}});
}
},
async down(db, client) {
await db.collection('User').updateMany({}, {$unset: {isEmailVerified: true}});
},
};
module.exports = {
async up(db, client) {
const cursor = await db.collection('User').find();
while (await cursor.hasNext()) {
const doc = await cursor.next();
const nickname = doc.email.split('@')[0];
await db.collection('User').updateOne({_id: doc._id}, {$set: {nickname: nickname}});
}
},
async down(db, client) {
await db.collection('User').updateMany({}, {$unset: {nickname: true}});
},
};
module.exports = {
async up(db, client) {
const cursor = await db.collection('User').find();
while (await cursor.hasNext()) {
const doc = await cursor.next();
const family = doc.username.split(' ')[1];
await db.collection('User').updateOne({_id: doc._id}, {$set: {family: family}});
}
},
async down(db, client) {
await db.collection('User').updateMany({}, {$unset: {family: true}});
},
};