mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
updated upgrade script to use mongo or redis
This commit is contained in:
8
app.js
8
app.js
@@ -154,10 +154,12 @@
|
||||
nconf.file({
|
||||
file: __dirname + '/config.json'
|
||||
});
|
||||
meta = require('./src/meta.js');
|
||||
require('./src/database').init(function(err) {
|
||||
meta = require('./src/meta.js');
|
||||
|
||||
meta.configs.init(function () {
|
||||
require('./src/upgrade').upgrade();
|
||||
meta.configs.init(function () {
|
||||
require('./src/upgrade').upgrade();
|
||||
});
|
||||
});
|
||||
} else/* if (nconf.get('help') */{
|
||||
winston.info('Usage: node app [options] [arguments]');
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
|
||||
|
||||
var nconf = require('nconf');
|
||||
db = require('./database/' + nconf.get('database'));
|
||||
var nconf = require('nconf'),
|
||||
databaseType = nconf.get('database');
|
||||
|
||||
if(!databaseType) {
|
||||
winston.info('Database type not set! Run npm app --setup');
|
||||
process.exit();
|
||||
}
|
||||
|
||||
var db = require('./database/' + databaseType);
|
||||
|
||||
module.exports = db;
|
||||
@@ -20,6 +20,8 @@
|
||||
process.exit();
|
||||
}
|
||||
|
||||
module.client = db;
|
||||
|
||||
module.sessionStore = new mongoStore({
|
||||
db: db
|
||||
});
|
||||
|
||||
@@ -295,9 +295,7 @@ var async = require('async'),
|
||||
}, next);
|
||||
},
|
||||
function (next) {
|
||||
// Upgrading schema
|
||||
var Upgrade = require('./upgrade');
|
||||
Upgrade.upgrade(next);
|
||||
require('./upgrade').upgrade(next);
|
||||
}
|
||||
], function (err) {
|
||||
if (err) {
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
var //db = require('./database'),
|
||||
|
||||
// TODO: temp until upgrade is figured out with dbal,
|
||||
RDB = require('./database/redis').client,
|
||||
|
||||
var db = require('./database'),
|
||||
async = require('async'),
|
||||
winston = require('winston'),
|
||||
notifications = require('./notifications'),
|
||||
categories = require('./categories'),
|
||||
nconf = require('nconf'),
|
||||
Upgrade = {},
|
||||
|
||||
schemaDate, thisSchemaDate;
|
||||
@@ -17,7 +14,7 @@ Upgrade.check = function(callback) {
|
||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
||||
var latestSchema = new Date(2013, 11, 2).getTime();
|
||||
|
||||
RDB.get('schemaDate', function(err, value) {
|
||||
db.get('schemaDate', function(err, value) {
|
||||
if (parseInt(value, 10) >= latestSchema) {
|
||||
callback(true);
|
||||
} else {
|
||||
@@ -27,6 +24,22 @@ Upgrade.check = function(callback) {
|
||||
};
|
||||
|
||||
Upgrade.upgrade = function(callback) {
|
||||
var databaseType = nconf.get('database');
|
||||
|
||||
if(databaseType === 'redis') {
|
||||
Upgrade.upgradeRedis(callback);
|
||||
} else if(databaseType === 'mongo') {
|
||||
Upgrade.upgradeMongo(callback);
|
||||
} else {
|
||||
winston.error('Unknown database type. Aborting upgrade');
|
||||
callback(new Error('unknown-database'));
|
||||
}
|
||||
};
|
||||
|
||||
Upgrade.upgradeRedis = function(callback) {
|
||||
|
||||
var RDB = db.client;
|
||||
|
||||
winston.info('Beginning Redis database schema update');
|
||||
|
||||
async.series([
|
||||
@@ -288,4 +301,42 @@ Upgrade.upgrade = function(callback) {
|
||||
});
|
||||
};
|
||||
|
||||
Upgrade.upgradeMongo = function(callback) {
|
||||
var MDB = db.client;
|
||||
|
||||
winston.info('Beginning Mongo database schema update');
|
||||
|
||||
async.series([
|
||||
function(next) {
|
||||
db.get('schemaDate', function(err, value) {
|
||||
console.log(schemaDate)
|
||||
schemaDate = value;
|
||||
thisSchemaDate = new Date(2013, 11, 6).getTime();
|
||||
next();
|
||||
});
|
||||
}
|
||||
// Add new schema updates here
|
||||
|
||||
], function(err) {
|
||||
if (!err) {
|
||||
db.set('schemaDate', thisSchemaDate, function(err) {
|
||||
if (!err) {
|
||||
winston.info('[upgrade] Mongo schema update complete!');
|
||||
if (callback) {
|
||||
callback(err);
|
||||
} else {
|
||||
process.exit();
|
||||
}
|
||||
} else {
|
||||
winston.error('[upgrade] Could not update NodeBB schema date!');
|
||||
process.exit();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
winston.error('[upgrade] Errors were encountered while updating the NodeBB schema: ' + err.message);
|
||||
process.exit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = Upgrade;
|
||||
Reference in New Issue
Block a user