mirror of
https://github.com/UniversityOfHelsinkiCS/ohtuilmo.git
synced 2026-10-12 19:03:41 +03:00
Try staging config for sequelize
Add ssl: true to sequelize config Add isProductionEnvironment() check for sequelize configs
This commit is contained in:
+33
-28
@@ -1,32 +1,37 @@
|
||||
require('dotenv').config()
|
||||
|
||||
module.exports = {
|
||||
"development": {
|
||||
"username": "postgres",
|
||||
"database": "dev_postgres",
|
||||
"port": "5432",
|
||||
"host": "localhost",
|
||||
"dialect": "postgres",
|
||||
"operatorsAliases": false,
|
||||
"pool": {
|
||||
"max": 5,
|
||||
"min": 0,
|
||||
"acquire": 10000,
|
||||
"idle": 300000000
|
||||
}
|
||||
}, "staging": {
|
||||
"username": process.env.DB_USERNAME,
|
||||
"database": process.env.DB_NAME,
|
||||
"port": process.env.DB_PORT,
|
||||
"host": process.env.DB_HOST,
|
||||
"password": process.env.DB_PASSWORD,
|
||||
"dialect": "postgres",
|
||||
"operatorsAliases": false,
|
||||
"pool": {
|
||||
"max": 5,
|
||||
"min": 0,
|
||||
"acquire": 10000,
|
||||
"idle": 300000000
|
||||
}
|
||||
}
|
||||
development: {
|
||||
username: 'postgres',
|
||||
database: 'dev_postgres',
|
||||
port: '5432',
|
||||
host: 'localhost',
|
||||
dialect: 'postgres',
|
||||
operatorsAliases: false,
|
||||
pool: {
|
||||
max: 5,
|
||||
min: 0,
|
||||
acquire: 10000,
|
||||
idle: 300000000,
|
||||
},
|
||||
},
|
||||
staging: {
|
||||
username: process.env.DB_USERNAME,
|
||||
database: process.env.DB_NAME,
|
||||
port: process.env.DB_PORT,
|
||||
host: process.env.DB_HOST,
|
||||
password: process.env.DB_PASSWORD,
|
||||
dialect: 'postgres',
|
||||
operatorsAliases: false,
|
||||
pool: {
|
||||
max: 5,
|
||||
min: 0,
|
||||
acquire: 10000,
|
||||
idle: 300000000,
|
||||
},
|
||||
ssl: true,
|
||||
dialectOptions: {
|
||||
ssl: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const { isProductionEnvironment } = require('./utils/index')
|
||||
const Sequelize = require('sequelize')
|
||||
const config = require('../config/sequelize.js')
|
||||
|
||||
@@ -7,8 +8,11 @@ db.connect = () => {
|
||||
const sequelizeConfig = config[process.env.NODE_ENV]
|
||||
|
||||
let sequelize
|
||||
if (process.env.DATABASE_URL) {
|
||||
sequelize = new Sequelize(process.env.DATABASE_URL, { logging: true, dialect: 'postgres' })
|
||||
if (isProductionEnvironment()) {
|
||||
sequelize = new Sequelize(process.env.DATABASE_URL, {
|
||||
logging: true,
|
||||
dialect: 'postgres',
|
||||
})
|
||||
} else {
|
||||
sequelize = new Sequelize(sequelizeConfig)
|
||||
}
|
||||
|
||||
+12
-7
@@ -12,16 +12,16 @@ const randomstring = require('randomstring')
|
||||
const msgTypeToDbColumn = {
|
||||
topicAccepted: {
|
||||
finnish: 'topic_accepted_fin',
|
||||
english: 'topic_accepted_eng'
|
||||
english: 'topic_accepted_eng',
|
||||
},
|
||||
topicRejected: {
|
||||
finnish: 'topic_rejected_fin',
|
||||
english: 'topic_rejected_eng'
|
||||
english: 'topic_rejected_eng',
|
||||
},
|
||||
customerReviewLink: {
|
||||
finnish: 'customer_review_link_fin',
|
||||
english: 'customer_review_link_eng'
|
||||
}
|
||||
english: 'customer_review_link_eng',
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,7 +33,7 @@ const dbColumnToMsgType = {
|
||||
topic_rejected_fin: { type: 'topicRejected', language: 'finnish' },
|
||||
topic_rejected_eng: { type: 'topicRejected', language: 'english' },
|
||||
customer_review_link_fin: { type: 'customerReviewLink', language: 'finnish' },
|
||||
customer_review_link_eng: { type: 'customerReviewLink', language: 'english' }
|
||||
customer_review_link_eng: { type: 'customerReviewLink', language: 'english' },
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,18 +56,23 @@ const templateNameToEmailType = (templateName) =>
|
||||
* is same as ↓
|
||||
* pipe(trim, uppercase, reverse)(str)
|
||||
*/
|
||||
const pipe = (...fns) => (value) => fns.reduce((v, fn) => fn(v), value)
|
||||
const pipe =
|
||||
(...fns) =>
|
||||
(value) =>
|
||||
fns.reduce((v, fn) => fn(v), value)
|
||||
|
||||
const getRandomId = () => {
|
||||
return 'a' + randomstring.generate(16)
|
||||
}
|
||||
|
||||
const isDevelopmentEnvironment = () => process.env.NODE_ENV === 'development'
|
||||
const isProductionEnvironment = () => process.env.NODE_ENV === 'production'
|
||||
|
||||
module.exports = {
|
||||
emailTypeToTemplateName,
|
||||
templateNameToEmailType,
|
||||
pipe,
|
||||
getRandomId,
|
||||
isDevelopmentEnvironment
|
||||
isDevelopmentEnvironment,
|
||||
isProductionEnvironment,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user