2017-06-26 00:21:33 +00:00
|
|
|
// @flow
|
2020-06-20 20:59:15 +00:00
|
|
|
import Sequelize from "sequelize";
|
|
|
|
import EncryptedField from "sequelize-encrypted";
|
2021-09-15 01:04:35 +00:00
|
|
|
import Logger from "./logging/logger";
|
2016-04-29 05:25:37 +00:00
|
|
|
|
2020-08-22 15:27:42 +00:00
|
|
|
const isProduction = process.env.NODE_ENV === "production";
|
2020-09-04 19:51:48 +00:00
|
|
|
const isSSLDisabled = process.env.PGSSLMODE === "disable";
|
2020-08-22 15:27:42 +00:00
|
|
|
|
2020-08-21 03:19:44 +00:00
|
|
|
export const encryptedFields = () =>
|
|
|
|
EncryptedField(Sequelize, process.env.SECRET_KEY);
|
2016-04-29 05:25:37 +00:00
|
|
|
|
|
|
|
export const DataTypes = Sequelize;
|
2017-12-26 13:02:26 +00:00
|
|
|
export const Op = Sequelize.Op;
|
2016-04-29 05:25:37 +00:00
|
|
|
|
2021-07-26 22:51:50 +00:00
|
|
|
export const sequelize = new Sequelize(
|
|
|
|
process.env.DATABASE_URL || process.env.DATABASE_CONNECTION_POOL_URL,
|
|
|
|
{
|
2021-09-15 01:04:35 +00:00
|
|
|
logging: (msg) => Logger.debug("database", msg),
|
2021-07-26 22:51:50 +00:00
|
|
|
typeValidation: true,
|
|
|
|
dialectOptions: {
|
|
|
|
ssl:
|
|
|
|
isProduction && !isSSLDisabled
|
|
|
|
? {
|
|
|
|
// Ref.: https://github.com/brianc/node-postgres/issues/2009
|
|
|
|
rejectUnauthorized: false,
|
|
|
|
}
|
|
|
|
: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|