More changes for db migration
This commit is contained in:
parent
de0284e48a
commit
889dc02945
33 changed files with 740 additions and 100 deletions
46
migrate/migrate-malwares.js
Normal file
46
migrate/migrate-malwares.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
import co from 'co';
|
||||
|
||||
import models from '../models';
|
||||
import { mongo } from '../lib/mongo';
|
||||
|
||||
import debugname from 'debug';
|
||||
const debug = debugname('hostr:db');
|
||||
let db;
|
||||
|
||||
|
||||
co(function *sync() {
|
||||
debug('Syncing schema');
|
||||
yield models.sequelize.sync();
|
||||
debug('Schema synced');
|
||||
db = yield mongo;
|
||||
|
||||
const files = db.Files.find({}, {
|
||||
sort: [['time_added', 'desc']],
|
||||
skip: 0,
|
||||
});
|
||||
debug('fetched files');
|
||||
|
||||
while (true) {
|
||||
const file = yield files.next();
|
||||
if (!file) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!file.time_added || !file.file_size || !file.malware) {
|
||||
continue;
|
||||
}
|
||||
|
||||
yield models.malware.upsert({
|
||||
fileId: file._id,
|
||||
positives: file.virustotal ? file.virustotal.positives : 100,
|
||||
virustotal: file.virustotal || null,
|
||||
}, { /* logging: false */ });
|
||||
}
|
||||
|
||||
models.sequelize.close();
|
||||
db.close();
|
||||
}).catch((err) => {
|
||||
models.sequelize.close();
|
||||
db.close();
|
||||
debug(err);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue