added migration to add channelName to Claim table

This commit is contained in:
bill bittner 2017-10-25 15:37:11 -07:00
parent 12798051a9
commit 8f4c4ff44e
4 changed files with 12 additions and 113 deletions

View file

@ -221,9 +221,11 @@ module.exports = {
return db.resolveClaim(fileInfo.name, fileInfo.claimId);
})
.then(resolveResult => {
logger.debug('resolve result >>', resolveResult);
fileInfo['thumbnail'] = chooseThumbnail(resolveResult, DEFAULT_THUMBNAIL);
fileInfo['title'] = resolveResult.title;
fileInfo['description'] = resolveResult.description;
if (resolveResult.certificateId) { fileInfo['certificateId'] = resolveResult.certificateId };
showFile(fileInfo, res);
return fileInfo;
})

View file

@ -1,79 +0,0 @@
module.exports = {
up: (queryInterface, Sequelize) => {
// logic for transforming into the new state
const p1 = queryInterface.removeColumn(
'Certificate',
'UserId'
);
const p2 = queryInterface.addColumn(
'Certificate',
'ChannelId',
{
type : Sequelize.INTEGER,
allowNull: true,
}
);
const p3 = queryInterface.addConstraint(
'Certificate',
['ChannelId'],
{
type : 'FOREIGN KEY',
name : 'Certificate_ibfk_1',
references: {
table: 'Channel',
field: 'id',
},
onUpdate: 'cascade',
onDelete: 'cascade',
}
);
const p4 = queryInterface.changeColumn(
'Claim',
'FileId',
{
type : Sequelize.INTEGER,
allowNull: true,
}
);
const p5 = queryInterface.addConstraint(
'Claim',
['FileId'],
{
type : 'FOREIGN KEY',
name : 'Claim_ibfk_1',
references: {
table: 'File',
field: 'id',
},
onUpdate: 'cascade',
onDelete: 'cascade',
}
);
const p6 = queryInterface.removeColumn(
'File',
'UserId'
);
return Promise.all([p1, p2, p3, p4, p5, p6]);
},
down: (queryInterface, Sequelize) => {
// logic for reverting the changes
const p1 = queryInterface.addColumn(
'Certificate',
'UserId',
{
type : Sequelize.INTEGER,
allowNull: true,
}
);
const p2 = queryInterface.addColumn(
'File',
'UserId',
{
type : Sequelize.INTEGER,
allowNull: true,
}
);
return Promise.all([p1, p2]);
},
};

View file

@ -2,45 +2,21 @@ module.exports = {
up: (queryInterface, Sequelize) => {
// logic for transforming into the new state
const p1 = queryInterface.addColumn(
'User',
'userName',
{
type : Sequelize.STRING,
allowNull: true,
}
);
const p2 = queryInterface.removeColumn(
'User',
'channelName'
);
const p3 = queryInterface.removeColumn(
'User',
'channelClaimId'
);
return Promise.all([p1, p2, p3]);
},
down: (queryInterface, Sequelize) => {
// logic for reverting the changes
const p1 = queryInterface.removeColumn(
'User',
'userName'
);
const p2 = queryInterface.addColumn(
'User',
'Claim',
'channelName',
{
type : Sequelize.STRING,
allowNull: true,
}
);
const p3 = queryInterface.addColumn(
'User',
'channelClaimId',
{
type : Sequelize.STRING,
allowNull: true,
}
return Promise.all([p1]);
},
down: (queryInterface, Sequelize) => {
// logic for reverting the changes
const p1 = queryInterface.removeColumn(
'Claim',
'channelName'
);
return Promise.all([p1, p2, p3]);
return Promise.all([p1]);
},
};

View file

@ -235,7 +235,7 @@ db['getAllFreeClaims'] = (name) => {
db['resolveClaim'] = (name, claimId) => {
return new Promise((resolve, reject) => {
db
.sequelize.query(`SELECT name, claimId, outpoint, height, address, title, description, thumbnail FROM Claim WHERE name = '${name}' AND claimId = '${claimId}'`, { type: db.sequelize.QueryTypes.SELECT })
.sequelize.query(`SELECT name, claimId, outpoint, height, address, title, description, thumbnail, certificateId FROM Claim WHERE name = '${name}' AND claimId = '${claimId}'`, { type: db.sequelize.QueryTypes.SELECT })
.then(result => {
switch (result.length) {
case 0: