1 | const moment = require('moment');
|
2 | const mongoose = require('mongoose');
|
3 | const domain = require('../');
|
4 |
|
5 | async function main() {
|
6 | const oldConnection = await mongoose.createConnection(process.env.MONGOLAB_URI_OLD);
|
7 | const connection = await mongoose.createConnection(process.env.MONGOLAB_URI);
|
8 |
|
9 | const oldTaskRepo = new domain.repository.Task(oldConnection);
|
10 | const taskRepo = new domain.repository.Task(connection);
|
11 |
|
12 | const cursor = await oldTaskRepo.taskModel.find(
|
13 | {
|
14 | 'project.id': { $exists: true, $eq: 'sskts-production' },
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | status: {
|
21 | $in: [domain.factory.taskStatus.Ready, domain.factory.taskStatus.Running]
|
22 | }
|
23 | },
|
24 | { createdAt: 0, updatedAt: 0 }
|
25 | )
|
26 | .sort({ runsAt: 1 })
|
27 | .cursor();
|
28 | console.log('tasks found');
|
29 |
|
30 | let i = 0;
|
31 | await cursor.eachAsync(async (doc) => {
|
32 | i += 1;
|
33 | const task = doc.toObject();
|
34 | console.log('migrating task...', task.id, task.runsAt);
|
35 |
|
36 | delete task._id;
|
37 | delete task.id;
|
38 | await taskRepo.taskModel.create(task);
|
39 |
|
40 | console.log('added', task.id, i);
|
41 | });
|
42 |
|
43 | console.log(i, 'tasks migrated');
|
44 |
|
45 | }
|
46 |
|
47 | main().then(() => {
|
48 | console.log('success!');
|
49 | }).catch((error) => {
|
50 | console.error(error);
|
51 | process.exit(1);
|
52 | });
|