File size: 1,274 Bytes
1e92f2d |
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 |
exports.up = function(r, conn) {
return Promise.all([
r
.tableCreate('usersSettings')
.run(conn)
// Create secondary indexes
.then(() =>
// index user by username
r
.table('usersSettings')
.indexCreate('userId', r.row('userId'))
.run(conn)
)
.then(() =>
Promise.all([
// Get all user ids while we wait for the index to finish creating
r.table('users').withFields('id').map(user => user('id')).run(conn),
r.table('usersSettings').indexWait('userId').run(conn),
])
)
.then(([userIds]) => userIds.toArray())
.then(userIds =>
Promise.all(
userIds.map(id =>
r
.table('usersSettings')
.insert({
userId: id,
notifications: {
types: {
newMessageInThreads: {
email: true,
},
},
},
})
.run(conn)
)
)
)
.catch(err => {
console.log(err);
throw err;
}),
]);
};
exports.down = function(r, conn) {
return r.tableDrop('usersSettings').run(conn);
};
|