Make migration scripts

and use createdAt instead of _id
This commit is contained in:
syuilo
2018-04-02 23:19:07 +09:00
parent 5b80b6e901
commit 5ce6fa67d2
7 changed files with 90 additions and 4 deletions

View File

@ -6,6 +6,7 @@ export default FollowedLog;
export type IFollowedLog = {
_id: ObjectID;
createdAt: Date;
userId: ObjectID;
count: number;
};

View File

@ -6,6 +6,7 @@ export default FollowingLog;
export type IFollowingLog = {
_id: ObjectID;
createdAt: Date;
userId: ObjectID;
count: number;
};

View File

@ -24,6 +24,7 @@ export default ({ data }, done) => Following.findOne({ _id: data.following }).th
}),
promisedFollower.then(({ followingCount }) => FollowingLog.insert({
createdAt: data.following.createdAt,
userId: followerId,
count: followingCount + 1
})),
@ -36,6 +37,7 @@ export default ({ data }, done) => Following.findOne({ _id: data.following }).th
}),
promisedFollowee.then(({ followersCount }) => FollowedLog.insert({
createdAt: data.following.createdAt,
userId: followerId,
count: followersCount + 1
})),

View File

@ -42,10 +42,10 @@ module.exports = (params) => new Promise(async (res, rej) => {
for (let i = 0; i < 30; i++) {
graph.push(FollowedLog.findOne({
_id: { $lt: ObjectID.createFromTime(cursorTime / 1000) },
createdAt: { $lt: new Date(cursorTime / 1000) },
userId: user._id
}, {
sort: { _id: -1 },
sort: { createdAt: -1 },
}).then(log => {
cursorDate = new Date(today.getTime());
cursorTime = cursorDate.setDate(today.getDate() - i);

View File

@ -42,10 +42,10 @@ module.exports = (params) => new Promise(async (res, rej) => {
for (let i = 0; i < 30; i++) {
graph.push(FollowingLog.findOne({
_id: { $lt: ObjectID.createFromTime(cursorTime / 1000) },
createdAt: { $lt: new Date(cursorTime / 1000) },
userId: user._id
}, {
sort: { _id: -1 },
sort: { createdAt: -1 },
}).then(log => {
cursorDate = new Date(today.getTime());
cursorTime = cursorDate.setDate(today.getDate() - i);