diff --git a/app/lib/dal/fileDAL.js b/app/lib/dal/fileDAL.js index 92eb3a7452e2e3328d4593c280e48b50ed0b9a93..db3e96e6ccc3a1bc6fc61015ff75e0f9886dcae1 100644 --- a/app/lib/dal/fileDAL.js +++ b/app/lib/dal/fileDAL.js @@ -5,6 +5,7 @@ var _ = require('underscore'); var path = require('path'); var hashf = require('../hashf'); var wotb = require('../wot'); +var logger = require('../logger')('filedal'); var directory = require('../directory'); var Configuration = require('../entity/configuration'); var Membership = require('../entity/membership'); @@ -78,7 +79,13 @@ function FileDAL(params) { var currency = ''; this.init = () => co(function *() { - yield _.values(that.newDals).map((dal) => dal.init()); + let dalNames = _.keys(that.newDals); + for (let i = 0; i < dalNames.length; i++) { + logger.debug("Init DAL %s...", dalNames[i]); + let dal = that.newDals[dalNames[i]]; + yield dal.init(); + } + logger.debug("Upgrade database..."); yield that.metaDAL.upgradeDatabase(); }); diff --git a/app/lib/dal/fileDALs/confDAL.js b/app/lib/dal/fileDALs/confDAL.js index ec577c5ebcf15083addaecc553f7944b490ce7df..d6671dfb7227014cf9fb82688485e666e34b4fe2 100644 --- a/app/lib/dal/fileDALs/confDAL.js +++ b/app/lib/dal/fileDALs/confDAL.js @@ -18,7 +18,7 @@ function ConfDAL(rootPath, qioFS, parentCore, localDAL, AbstractStorage) { var logger = require('../../../lib/logger')(this.dal.profile); - this.init = () => null; + this.init = () => Promise.resolve(); this.getParameters = function() { return co(function *() { @@ -61,4 +61,4 @@ function ConfDAL(rootPath, qioFS, parentCore, localDAL, AbstractStorage) { }; this.saveConf = (confToSave) => that.coreFS.writeJSONDeep('conf.json', confToSave); -} \ No newline at end of file +} diff --git a/app/lib/dal/fileDALs/statDAL.js b/app/lib/dal/fileDALs/statDAL.js index d4a4de9707ae1a8c8cad2aee945ea47f0af9a565..3ed1bdad79af0a63d57eb70f32a49f745a54efca 100644 --- a/app/lib/dal/fileDALs/statDAL.js +++ b/app/lib/dal/fileDALs/statDAL.js @@ -15,7 +15,7 @@ function StatDAL(rootPath, qioFS, parentCore, localDAL, AbstractStorage) { AbstractStorage.call(this, rootPath, qioFS, parentCore, localDAL); - this.init = () => null; + this.init = () => Promise.resolve(); this.loadStats = () => that.coreFS.readJSON('stats.json').catch(() => {}); @@ -33,4 +33,4 @@ function StatDAL(rootPath, qioFS, parentCore, localDAL, AbstractStorage) { return that.coreFS.writeJSON('stats.json', stats); }); }; -} \ No newline at end of file +} diff --git a/app/lib/dal/sqliteDAL/MetaDAL.js b/app/lib/dal/sqliteDAL/MetaDAL.js index 7a4a8a38ab6209664dc0efc39ff0befe6856edbe..07e60848fa0a7eb28d940098f51a1403dace7dcd 100644 --- a/app/lib/dal/sqliteDAL/MetaDAL.js +++ b/app/lib/dal/sqliteDAL/MetaDAL.js @@ -3,7 +3,7 @@ */ var co = require('co'); -var logger = require('../../../../app/lib/logger')('linksDAL'); +var logger = require('../../../../app/lib/logger')('metaDAL'); var AbstractSQLite = require('./AbstractSQLite'); module.exports = MetaDAL; @@ -39,13 +39,13 @@ function MetaDAL(db) { 'version INTEGER NOT NULL,' + 'PRIMARY KEY (id)' + ');' + - 'INSERT INTO ' + that.table + ' VALUES (1,0);' + 'COMMIT;', []); }); this.upgradeDatabase = () => co(function *() { let version = yield that.getVersion(); while(migrations[version]) { + logger.debug("Upgrading from v%s to v%s...", version, version + 1); yield that.exec(migrations[version]); // Automated increment yield that.exec('UPDATE meta SET version = version + 1'); @@ -56,7 +56,12 @@ function MetaDAL(db) { this.getRow = () => that.sqlFindOne({ id: 1 }); this.getVersion = () => co(function *() { - let row = yield that.getRow(); - return row.version; + try { + let row = yield that.getRow(); + return row.version; + } catch(e) { + yield that.exec('INSERT INTO ' + that.table + ' VALUES (1,0);'); + return 0; + } }); }