Fix migrator (#831)

This commit is contained in:
Calvin Montgomery 2019-10-27 13:09:22 -07:00
parent 06b3916a6c
commit b0b22a7579
2 changed files with 9 additions and 3 deletions

View File

@ -50,7 +50,7 @@
"lint": "eslint src",
"pretest": "npm run lint",
"postinstall": "./postinstall.sh",
"server-dev": "babel -D --watch --source-maps --loose es6.destructuring,es6.forOf --out-dir lib/ src/",
"server-dev": "babel -D --watch --source-maps --loose es6.destructuring,es6.forOf --verbose --out-dir lib/ src/",
"generate-userscript": "$npm_node_execpath gdrive-userscript/generate-userscript $@ > www/js/cytube-google-drive.user.js",
"test": "mocha --recursive --exit test",
"integration-test": "mocha --recursive --exit integration_test"

View File

@ -6,6 +6,8 @@ import { DatabaseStore } from './dbstore';
import { sanitizeHTML } from '../xss';
import { ChannelNotFoundError } from '../errors';
const lookupAsync = Promise.promisify(require('../database/channels').lookup);
/* eslint no-console: off */
const EXPECTED_KEYS = [
@ -118,7 +120,11 @@ function migrate(src, dest, opts) {
}
}
return src.load(-1, name).then(data => {
let id;
return lookupAsync(name).then(chan => {
id = chan.id;
return src.load(id, name);
}).then(data => {
data = fixOldChandump(data);
Object.keys(data).forEach(key => {
if (opts.keyWhitelist.length > 0 &&
@ -129,7 +135,7 @@ function migrate(src, dest, opts) {
delete data[key];
}
});
return dest.save(name, data);
return dest.save(id, name, data);
}).then(() => {
console.log(`Migrated /${chanPath}/${name}`);
}).catch(ChannelNotFoundError, _err => {