added migration to change DOUBLE to DECIMAL
This commit is contained in:
parent
37315c6c66
commit
9dc4b2f151
9 changed files with 87 additions and 178 deletions
|
@ -1,26 +0,0 @@
|
|||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
// logic for transforming into the new state
|
||||
const p1 = queryInterface.changeColumn(
|
||||
'Claim',
|
||||
'amount',
|
||||
{
|
||||
type : Sequelize.DOUBLE,
|
||||
allowNull: true,
|
||||
}
|
||||
);
|
||||
return Promise.all([p1]);
|
||||
},
|
||||
down: (queryInterface, Sequelize) => {
|
||||
// logic for reverting the changes
|
||||
const p1 = queryInterface.changeColumn(
|
||||
'Claim',
|
||||
'amount',
|
||||
{
|
||||
type : Sequelize.STRING,
|
||||
allowNull: true,
|
||||
}
|
||||
);
|
||||
return Promise.all([p1]);
|
||||
},
|
||||
};
|
|
@ -1,74 +0,0 @@
|
|||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
// logic for transforming into the new state
|
||||
const p1 = queryInterface.changeColumn(
|
||||
'Certificate',
|
||||
'amount',
|
||||
{
|
||||
type : Sequelize.DOUBLE,
|
||||
allowNull: true,
|
||||
}
|
||||
);
|
||||
const p2 = queryInterface.changeColumn(
|
||||
'Certificate',
|
||||
'effectiveAmount',
|
||||
{
|
||||
type : Sequelize.DOUBLE,
|
||||
allowNull: true,
|
||||
}
|
||||
);
|
||||
const p3 = queryInterface.changeColumn(
|
||||
'Certificate',
|
||||
'height',
|
||||
{
|
||||
type : Sequelize.INTEGER,
|
||||
allowNull: true,
|
||||
}
|
||||
);
|
||||
const p4 = queryInterface.changeColumn(
|
||||
'Certificate',
|
||||
'validAtHeight',
|
||||
{
|
||||
type : Sequelize.INTEGER,
|
||||
allowNull: true,
|
||||
}
|
||||
);
|
||||
return Promise.all([p1, p2, p3, p4]);
|
||||
},
|
||||
down: (queryInterface, Sequelize) => {
|
||||
// logic for reverting the changes
|
||||
const p1 = queryInterface.changeColumn(
|
||||
'Certificate',
|
||||
'amount',
|
||||
{
|
||||
type : Sequelize.STRING,
|
||||
allowNull: true,
|
||||
}
|
||||
);
|
||||
const p2 = queryInterface.changeColumn(
|
||||
'Certificate',
|
||||
'effectiveAmount',
|
||||
{
|
||||
type : Sequelize.STRING,
|
||||
allowNull: true,
|
||||
}
|
||||
);
|
||||
const p3 = queryInterface.changeColumn(
|
||||
'Certificate',
|
||||
'height',
|
||||
{
|
||||
type : Sequelize.STRING,
|
||||
allowNull: true,
|
||||
}
|
||||
);
|
||||
const p4 = queryInterface.changeColumn(
|
||||
'Certificate',
|
||||
'validAtHeight',
|
||||
{
|
||||
type : Sequelize.STRING,
|
||||
allowNull: true,
|
||||
}
|
||||
);
|
||||
return Promise.all([p1, p2, p3, p4]);
|
||||
},
|
||||
};
|
42
migrations/ChangeCertificateColumnTypes2.js
Normal file
42
migrations/ChangeCertificateColumnTypes2.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
// logic for transforming into the new state
|
||||
const p1 = queryInterface.changeColumn(
|
||||
'Certificate',
|
||||
'amount',
|
||||
{
|
||||
type : Sequelize.DECIMAL(19, 8),
|
||||
allowNull: true,
|
||||
}
|
||||
);
|
||||
const p2 = queryInterface.changeColumn(
|
||||
'Certificate',
|
||||
'effectiveAmount',
|
||||
{
|
||||
type : Sequelize.DECIMAL(19, 8),
|
||||
allowNull: true,
|
||||
}
|
||||
);
|
||||
return Promise.all([p1, p2]);
|
||||
},
|
||||
down: (queryInterface, Sequelize) => {
|
||||
// logic for reverting the changes
|
||||
const p1 = queryInterface.changeColumn(
|
||||
'Certificate',
|
||||
'amount',
|
||||
{
|
||||
type : Sequelize.DOUBLE,
|
||||
allowNull: true,
|
||||
}
|
||||
);
|
||||
const p2 = queryInterface.changeColumn(
|
||||
'Certificate',
|
||||
'effectiveAmount',
|
||||
{
|
||||
type : Sequelize.DOUBLE,
|
||||
allowNull: true,
|
||||
}
|
||||
);
|
||||
return Promise.all([p1, p2]);
|
||||
},
|
||||
};
|
|
@ -2,6 +2,34 @@ module.exports = {
|
|||
up: (queryInterface, Sequelize) => {
|
||||
// logic for transforming into the new state
|
||||
const p1 = queryInterface.changeColumn(
|
||||
'Claim',
|
||||
'amount',
|
||||
{
|
||||
type : Sequelize.DECIMAL(19, 8),
|
||||
allowNull: true,
|
||||
}
|
||||
);
|
||||
const p2 = queryInterface.changeColumn(
|
||||
'Claim',
|
||||
'effectiveAmount',
|
||||
{
|
||||
type : Sequelize.DECIMAL(19, 8),
|
||||
allowNull: true,
|
||||
}
|
||||
);
|
||||
return Promise.all([p1, p2]);
|
||||
},
|
||||
down: (queryInterface, Sequelize) => {
|
||||
// logic for reverting the changes
|
||||
const p1 = queryInterface.changeColumn(
|
||||
'Claim',
|
||||
'amount',
|
||||
{
|
||||
type : Sequelize.DOUBLE,
|
||||
allowNull: true,
|
||||
}
|
||||
);
|
||||
const p2 = queryInterface.changeColumn(
|
||||
'Claim',
|
||||
'effectiveAmount',
|
||||
{
|
||||
|
@ -9,18 +37,6 @@ module.exports = {
|
|||
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]);
|
||||
return Promise.all([p1, p2]);
|
||||
},
|
||||
};
|
|
@ -1,26 +0,0 @@
|
|||
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]);
|
||||
},
|
||||
};
|
|
@ -1,26 +0,0 @@
|
|||
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]);
|
||||
},
|
||||
};
|
|
@ -25,7 +25,7 @@ function sortResult (result, longId) {
|
|||
return shortId;
|
||||
}
|
||||
|
||||
module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, DOUBLE, Op }) => {
|
||||
module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
|
||||
const Certificate = sequelize.define(
|
||||
'Certificate',
|
||||
{
|
||||
|
@ -34,7 +34,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D
|
|||
default: null,
|
||||
},
|
||||
amount: {
|
||||
type : DOUBLE,
|
||||
type : DECIMAL(19, 8),
|
||||
default: null,
|
||||
},
|
||||
claimId: {
|
||||
|
@ -54,7 +54,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D
|
|||
default: null,
|
||||
},
|
||||
effectiveAmount: {
|
||||
type : DOUBLE,
|
||||
type : DECIMAL(19, 8),
|
||||
default: null,
|
||||
},
|
||||
hasSignature: {
|
||||
|
|
|
@ -25,7 +25,7 @@ function sortResult (result, longId) {
|
|||
return shortId;
|
||||
}
|
||||
|
||||
module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DOUBLE }) => {
|
||||
module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
|
||||
const Claim = sequelize.define(
|
||||
'Claim',
|
||||
{
|
||||
|
@ -34,7 +34,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DOUBLE }) => {
|
|||
default: null,
|
||||
},
|
||||
amount: {
|
||||
type : DOUBLE,
|
||||
type : DECIMAL(19, 8),
|
||||
default: null,
|
||||
},
|
||||
claimId: {
|
||||
|
@ -54,7 +54,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DOUBLE }) => {
|
|||
default: null,
|
||||
},
|
||||
effectiveAmount: {
|
||||
type : DOUBLE,
|
||||
type : DECIMAL(19, 8),
|
||||
default: null,
|
||||
},
|
||||
hasSignature: {
|
||||
|
|
|
@ -2,19 +2,20 @@ const fs = require('fs');
|
|||
const path = require('path');
|
||||
const Sequelize = require('sequelize');
|
||||
const basename = path.basename(module.filename);
|
||||
const config = require('../config/speechConfig.js');
|
||||
const db = {};
|
||||
const logger = require('winston');
|
||||
|
||||
const config = require('../config/speechConfig.js');
|
||||
const database = config.sql.database;
|
||||
const username = config.sql.username;
|
||||
const password = config.sql.password;
|
||||
const db = {};
|
||||
|
||||
// set sequelize options
|
||||
const sequelize = new Sequelize(database, username, password, {
|
||||
host : 'localhost',
|
||||
dialect: 'mysql',
|
||||
logging: false,
|
||||
pool : {
|
||||
host : 'localhost',
|
||||
dialect : 'mysql',
|
||||
dialectOptions: {decimalNumbers: true}, // fix to ensure DECIMAL will not be stored as a string
|
||||
logging : false,
|
||||
pool : {
|
||||
max : 5,
|
||||
min : 0,
|
||||
idle : 10000,
|
||||
|
@ -53,6 +54,7 @@ Object.keys(db).forEach(modelName => {
|
|||
db.sequelize = sequelize;
|
||||
db.Sequelize = Sequelize;
|
||||
|
||||
// add an 'upsert' method to the db object
|
||||
db.upsert = (Model, values, condition, tableName) => {
|
||||
return Model
|
||||
.findOne({ where: condition })
|
||||
|
@ -70,6 +72,7 @@ db.upsert = (Model, values, condition, tableName) => {
|
|||
});
|
||||
};
|
||||
|
||||
// add a 'getTrendingClaims' method to the db object
|
||||
db.getTrendingClaims = (startDate) => {
|
||||
return db.sequelize.query(`SELECT COUNT(*), File.* FROM Request LEFT JOIN File ON Request.FileId = File.id WHERE FileId IS NOT NULL AND nsfw != 1 AND trendingEligible = 1 AND Request.createdAt > "${startDate}" GROUP BY FileId ORDER BY COUNT(*) DESC LIMIT 25;`, { type: db.sequelize.QueryTypes.SELECT });
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue