Skip to content

Commit

Permalink
Hotfix for db migration for sequelize (#1907)
Browse files Browse the repository at this point in the history
* Updates for prerelease testing

* Added logic for sequelize db migration to be executed after the update is completed

* Updated ot-node version, removed hotfix
  • Loading branch information
djordjekovac authored Apr 8, 2022
1 parent fdfe53d commit 5b5f2e8
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 14,642 deletions.
16 changes: 15 additions & 1 deletion ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const constants = require('./modules/constants');
const pjson = require('./package.json');
const configjson = require('./config/config.json');

let updateFilePath;

class OTNode {
constructor(config) {
this.initializeConfiguration(config);
Expand Down Expand Up @@ -74,6 +76,11 @@ class OTNode {

async initializeAutoUpdate() {
try {
updateFilePath = `./${this.config.appDataPath}/UPDATED`;
// check if UPDATE file exists if yes set flag updated true
if (fs.existsSync(updateFilePath)) {
this.config.otNodeUpdated = true;
}
if (!this.config.autoUpdate.enabled) {
return;
}
Expand All @@ -82,6 +89,7 @@ class OTNode {
repository: 'https://github.com/OriginTrail/ot-node',
branch: this.config.autoUpdate.branch,
tempLocation: this.config.autoUpdate.backupDirectory,
executeOnComplete: `touch ${updateFilePath}`,
exitOnComplete: true,
};

Expand Down Expand Up @@ -120,7 +128,13 @@ class OTNode {
this.logger.info('Operational database module: sequelize implementation');
// eslint-disable-next-line global-require
const db = require('./models');
execSync('npx sequelize --config=./config/sequelizeConfig.js db:migrate');
// todo change if statement to if (this.config.otNodeUpdated);
if (process.env.NODE_ENV !== 'test') {
execSync('npx sequelize --config=./config/sequelizeConfig.js db:migrate');
// todo remove UPDATE file for next release
// execSync('rm ${updateFilePath}');
// this.config.otNodeUpdated = false;
}
await db.sequelize.sync();
} catch (e) {
this.logger.error({
Expand Down
Loading

0 comments on commit 5b5f2e8

Please sign in to comment.