added migrations for Claim column types

This commit is contained in:
bill bittner 2017-11-07 14:47:41 -08:00
parent 912363e936
commit dce1c32288
6 changed files with 88 additions and 52 deletions

View file

@ -1,5 +1,5 @@
const path = require('path'); const path = require('path');
module.exports = { module.exports = {
'config': path.resolve('config', 'sequelizeCliConfig.json'), 'config': path.resolve('config', 'sequelizeCliConfig.js'),
} }

View file

@ -1,11 +1,11 @@
module.exports = { module.exports = {
up: (queryInterface, Sequelize) => { up: (queryInterface, Sequelize) => {
// logic for transforming into the new state // logic for transforming into the new state
const p1 = queryInterface.addColumn( const p1 = queryInterface.changeColumn(
'Claim', 'Claim',
'channelName', 'amount',
{ {
type : Sequelize.STRING, type : Sequelize.DOUBLE,
allowNull: true, allowNull: true,
} }
); );
@ -13,9 +13,13 @@ module.exports = {
}, },
down: (queryInterface, Sequelize) => { down: (queryInterface, Sequelize) => {
// logic for reverting the changes // logic for reverting the changes
const p1 = queryInterface.removeColumn( const p1 = queryInterface.changeColumn(
'Claim', 'Claim',
'channelName' 'amount',
{
type : Sequelize.STRING,
allowNull: true,
}
); );
return Promise.all([p1]); return Promise.all([p1]);
}, },

View file

@ -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]);
},
};

View file

@ -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]);
},
};

View file

@ -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]);
},
};

View file

@ -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
},
};