mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 20:16:04 +01:00
change db.set/get to use data field instead of value
This commit is contained in:
@@ -66,7 +66,7 @@ module.exports = function (db, module) {
|
||||
if (!key) {
|
||||
return callback();
|
||||
}
|
||||
module.getObjectField(key, 'value', callback);
|
||||
module.getObjectField(key, 'data', callback);
|
||||
};
|
||||
|
||||
module.set = function (key, value, callback) {
|
||||
@@ -74,7 +74,7 @@ module.exports = function (db, module) {
|
||||
if (!key) {
|
||||
return callback();
|
||||
}
|
||||
var data = { value: value };
|
||||
var data = { data: value };
|
||||
module.setObject(key, data, callback);
|
||||
};
|
||||
|
||||
@@ -115,7 +115,7 @@ module.exports = function (db, module) {
|
||||
return callback(null, 'set');
|
||||
} else if (keys.length === 3 && data.hasOwnProperty('_key') && data.hasOwnProperty('array')) {
|
||||
return callback(null, 'list');
|
||||
} else if (keys.length === 3 && data.hasOwnProperty('_key') && data.hasOwnProperty('value')) {
|
||||
} else if (keys.length === 3 && data.hasOwnProperty('_key') && data.hasOwnProperty('data')) {
|
||||
return callback(null, 'string');
|
||||
}
|
||||
callback(null, 'hash');
|
||||
|
||||
67
src/upgrades/1.7.3/key_value_schema_change.js
Normal file
67
src/upgrades/1.7.3/key_value_schema_change.js
Normal file
@@ -0,0 +1,67 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
|
||||
var db = require('../../database');
|
||||
|
||||
module.exports = {
|
||||
name: 'Change the schema of simple keys so they don\'t use value field (mongodb only)',
|
||||
timestamp: Date.UTC(2017, 11, 18),
|
||||
method: function (callback) {
|
||||
var configJSON = require('../../../config.json');
|
||||
var isMongo = configJSON.hasOwnProperty('mongo') && configJSON.database === 'mongo';
|
||||
var progress = this.progress;
|
||||
if (!isMongo) {
|
||||
return callback();
|
||||
}
|
||||
var client = db.client;
|
||||
var cursor;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
client.collection('objects').count({
|
||||
_key: { $exists: true },
|
||||
value: { $exists: true },
|
||||
score: { $exists: false },
|
||||
}, next);
|
||||
},
|
||||
function (count, next) {
|
||||
progress.total = count;
|
||||
cursor = client.collection('objects').find({
|
||||
_key: { $exists: true },
|
||||
value: { $exists: true },
|
||||
score: { $exists: false },
|
||||
}).batchSize(1000);
|
||||
|
||||
var done = false;
|
||||
async.whilst(
|
||||
function () {
|
||||
return !done;
|
||||
},
|
||||
function (next) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
cursor.next(next);
|
||||
},
|
||||
function (item, next) {
|
||||
progress.incr();
|
||||
if (item === null) {
|
||||
done = true;
|
||||
return next();
|
||||
}
|
||||
|
||||
if (Object.keys(item).length === 3 && item.hasOwnProperty('_key') && item.hasOwnProperty('value')) {
|
||||
client.collection('objects').update({ _key: item._key }, { $rename: { value: 'data' } }, next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
next(err);
|
||||
});
|
||||
},
|
||||
next
|
||||
);
|
||||
},
|
||||
], callback);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user