From b0b22a7579456dfb797d351de2366cc02c851571 Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Sun, 27 Oct 2019 13:09:22 -0700 Subject: [PATCH] Fix migrator (#831) --- package.json | 2 +- src/channel-storage/migrator.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 35e4783c..28ac4c9e 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/channel-storage/migrator.js b/src/channel-storage/migrator.js index 176f099f..d8c7c005 100644 --- a/src/channel-storage/migrator.js +++ b/src/channel-storage/migrator.js @@ -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 => {