mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 20:16:04 +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({
|
nconf.file({
|
||||||
file: __dirname + '/config.json'
|
file: __dirname + '/config.json'
|
||||||
});
|
});
|
||||||
meta = require('./src/meta.js');
|
require('./src/database').init(function(err) {
|
||||||
|
meta = require('./src/meta.js');
|
||||||
|
|
||||||
meta.configs.init(function () {
|
meta.configs.init(function () {
|
||||||
require('./src/upgrade').upgrade();
|
require('./src/upgrade').upgrade();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else/* if (nconf.get('help') */{
|
} else/* if (nconf.get('help') */{
|
||||||
winston.info('Usage: node app [options] [arguments]');
|
winston.info('Usage: node app [options] [arguments]');
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
|
|
||||||
|
|
||||||
var nconf = require('nconf');
|
var nconf = require('nconf'),
|
||||||
db = require('./database/' + nconf.get('database'));
|
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;
|
module.exports = db;
|
||||||
@@ -20,6 +20,8 @@
|
|||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.client = db;
|
||||||
|
|
||||||
module.sessionStore = new mongoStore({
|
module.sessionStore = new mongoStore({
|
||||||
db: db
|
db: db
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -295,9 +295,7 @@ var async = require('async'),
|
|||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
// Upgrading schema
|
require('./upgrade').upgrade(next);
|
||||||
var Upgrade = require('./upgrade');
|
|
||||||
Upgrade.upgrade(next);
|
|
||||||
}
|
}
|
||||||
], function (err) {
|
], function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var //db = require('./database'),
|
var db = require('./database'),
|
||||||
|
|
||||||
// TODO: temp until upgrade is figured out with dbal,
|
|
||||||
RDB = require('./database/redis').client,
|
|
||||||
|
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
winston = require('winston'),
|
winston = require('winston'),
|
||||||
notifications = require('./notifications'),
|
notifications = require('./notifications'),
|
||||||
categories = require('./categories'),
|
categories = require('./categories'),
|
||||||
|
nconf = require('nconf'),
|
||||||
Upgrade = {},
|
Upgrade = {},
|
||||||
|
|
||||||
schemaDate, thisSchemaDate;
|
schemaDate, thisSchemaDate;
|
||||||
@@ -17,7 +14,7 @@ Upgrade.check = function(callback) {
|
|||||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
||||||
var latestSchema = new Date(2013, 11, 2).getTime();
|
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) {
|
if (parseInt(value, 10) >= latestSchema) {
|
||||||
callback(true);
|
callback(true);
|
||||||
} else {
|
} else {
|
||||||
@@ -27,6 +24,22 @@ Upgrade.check = function(callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Upgrade.upgrade = 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');
|
winston.info('Beginning Redis database schema update');
|
||||||
|
|
||||||
async.series([
|
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;
|
module.exports = Upgrade;
|
||||||
Reference in New Issue
Block a user