From dce1c32288762f64540888b8d7fdf440a617edd2 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Tue, 7 Nov 2017 14:47:41 -0800 Subject: [PATCH] added migrations for Claim column types --- .sequelizerc | 2 +- ...meToClaim.js => ChangeAmountColumnType.js} | 14 ++++-- migrations/ChangeEffectiveAmountColumnType.js | 26 +++++++++++ migrations/ChangeHeightColumnType.js | 26 +++++++++++ migrations/ChangeValidAtHeightColumnType.js | 26 +++++++++++ migrations/UpdateUserPasswords5.js | 46 ------------------- 6 files changed, 88 insertions(+), 52 deletions(-) rename migrations/{AddChannelNameToClaim.js => ChangeAmountColumnType.js} (65%) create mode 100644 migrations/ChangeEffectiveAmountColumnType.js create mode 100644 migrations/ChangeHeightColumnType.js create mode 100644 migrations/ChangeValidAtHeightColumnType.js delete mode 100644 migrations/UpdateUserPasswords5.js diff --git a/.sequelizerc b/.sequelizerc index e671871a..f2daa0b6 100644 --- a/.sequelizerc +++ b/.sequelizerc @@ -1,5 +1,5 @@ const path = require('path'); module.exports = { - 'config': path.resolve('config', 'sequelizeCliConfig.json'), + 'config': path.resolve('config', 'sequelizeCliConfig.js'), } \ No newline at end of file diff --git a/migrations/AddChannelNameToClaim.js b/migrations/ChangeAmountColumnType.js similarity index 65% rename from migrations/AddChannelNameToClaim.js rename to migrations/ChangeAmountColumnType.js index b9ac1da8..434e10a3 100644 --- a/migrations/AddChannelNameToClaim.js +++ b/migrations/ChangeAmountColumnType.js @@ -1,11 +1,11 @@ module.exports = { up: (queryInterface, Sequelize) => { // logic for transforming into the new state - const p1 = queryInterface.addColumn( + const p1 = queryInterface.changeColumn( 'Claim', - 'channelName', + 'amount', { - type : Sequelize.STRING, + type : Sequelize.DOUBLE, allowNull: true, } ); @@ -13,9 +13,13 @@ module.exports = { }, down: (queryInterface, Sequelize) => { // logic for reverting the changes - const p1 = queryInterface.removeColumn( + const p1 = queryInterface.changeColumn( 'Claim', - 'channelName' + 'amount', + { + type : Sequelize.STRING, + allowNull: true, + } ); return Promise.all([p1]); }, diff --git a/migrations/ChangeEffectiveAmountColumnType.js b/migrations/ChangeEffectiveAmountColumnType.js new file mode 100644 index 00000000..63f48e15 --- /dev/null +++ b/migrations/ChangeEffectiveAmountColumnType.js @@ -0,0 +1,26 @@ +module.exports = { + up: (queryInterface, Sequelize) => { + // logic for transforming into the new state + const p1 = queryInterface.changeColumn( + 'Claim', + 'effectiveAmount', + { + type : Sequelize.DOUBLE, + allowNull: true, + } + ); + return Promise.all([p1]); + }, + down: (queryInterface, Sequelize) => { + // logic for reverting the changes + const p1 = queryInterface.changeColumn( + 'Claim', + 'effectiveAmount', + { + type : Sequelize.STRING, + allowNull: true, + } + ); + return Promise.all([p1]); + }, +}; diff --git a/migrations/ChangeHeightColumnType.js b/migrations/ChangeHeightColumnType.js new file mode 100644 index 00000000..c6d32223 --- /dev/null +++ b/migrations/ChangeHeightColumnType.js @@ -0,0 +1,26 @@ +module.exports = { + up: (queryInterface, Sequelize) => { + // logic for transforming into the new state + const p1 = queryInterface.changeColumn( + 'Claim', + 'height', + { + type : Sequelize.INTEGER, + allowNull: true, + } + ); + return Promise.all([p1]); + }, + down: (queryInterface, Sequelize) => { + // logic for reverting the changes + const p1 = queryInterface.changeColumn( + 'Claim', + 'height', + { + type : Sequelize.STRING, + allowNull: true, + } + ); + return Promise.all([p1]); + }, +}; diff --git a/migrations/ChangeValidAtHeightColumnType.js b/migrations/ChangeValidAtHeightColumnType.js new file mode 100644 index 00000000..3f87aa4c --- /dev/null +++ b/migrations/ChangeValidAtHeightColumnType.js @@ -0,0 +1,26 @@ +module.exports = { + up: (queryInterface, Sequelize) => { + // logic for transforming into the new state + const p1 = queryInterface.changeColumn( + 'Claim', + 'validAtHeight', + { + type : Sequelize.INTEGER, + allowNull: true, + } + ); + return Promise.all([p1]); + }, + down: (queryInterface, Sequelize) => { + // logic for reverting the changes + const p1 = queryInterface.changeColumn( + 'Claim', + 'validAtHeight', + { + type : Sequelize.STRING, + allowNull: true, + } + ); + return Promise.all([p1]); + }, +}; diff --git a/migrations/UpdateUserPasswords5.js b/migrations/UpdateUserPasswords5.js deleted file mode 100644 index f911c86e..00000000 --- a/migrations/UpdateUserPasswords5.js +++ /dev/null @@ -1,46 +0,0 @@ -const db = require('../models'); -const bcrypt = require('bcrypt'); -const logger = require('winston'); - -module.exports = { - up: (queryInterface, Sequelize) => { - // get all the users - return db.User - .findAll() - .then((users) => { - // create an array of promises, with each promise bcrypting a password and updating the record - const promises = users.map((record) => { - // bcrypt - // generate a salt string to use for hashing - return new Promise((resolve, reject) => { - bcrypt.genSalt((saltError, salt) => { - if (saltError) { - logger.error('salt error', saltError); - reject(saltError); - return; - } - // generate a hashed version of the user's password - bcrypt.hash(record.password, salt, (hashError, hash) => { - // if there is an error with the hash generation return the error - if (hashError) { - logger.error('hash error', hashError); - reject(hashError); - return; - } - // replace the password string with the hash password value - resolve(queryInterface.sequelize.query(`UPDATE User SET User.password = "${hash}" WHERE User.id = ${record.id}`)); - }); - }); - }); - }); - // return the array of promises - return Promise.all(promises); - }) - .catch(error => { - logger.error('error prepping promises array', error); - }); - }, - down: (queryInterface, Sequelize) => { - // logic for reverting the changes - }, -};